File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -490,6 +490,40 @@ $query->addOrder($order1, $order2);
490
490
$query->addOrder($order3);
491
491
```
492
492
493
+ ## Modifying the column list: columns and projections
494
+ Query will return all columns of the queried table by default. However, you can modify
495
+ the column list:
496
+
497
+ ```
498
+ // Select myColumn only
499
+ $query->addColumn(Projections::property('myColumn'));
500
+
501
+ // Add another column
502
+ $query->addColumn(Projections::property('anotherColumn'));
503
+ ```
504
+
505
+ Please notice that the first call to ` addColumn ` will remove the ` * ` retrieval
506
+ on the query. Any subsequent call will enhance the list. The same result can be
507
+ achieved with:
508
+
509
+ ```
510
+ $query->setColumns(Projections::property('myColumn'), Projections::property('anotherColumn'));
511
+ ```
512
+
513
+ And there are some shortcuts:
514
+
515
+ ```
516
+ // Variant 1: flexible argument list
517
+ $query1->addColumn(Projections::property('myColumn'), Projections::property('anotherColumn'));
518
+
519
+ // Variant 2: use #properties() method in Projections
520
+ $query1->addColumn(Projections::properties('myColumn', 'anotherColumn'));
521
+ ```
522
+
523
+ ** Attention:** A call to ` setColumns() ` or ` setProjection() ` (deprecated alternative) will always remove
524
+ the result class definition in the query object. This will ensure compatibility with previous versions.
525
+ So you would need to call ` setResultClass() ` in case you want the query to return other classes than ` stdClass ` .
526
+
493
527
## Getting the result
494
528
That's the most easiest part:
495
529
You can’t perform that action at this time.
0 commit comments