Skip to content

Commit 465d8d6

Browse files
committed
Document select clause creation
1 parent 0e36448 commit 465d8d6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,40 @@ $query->addOrder($order1, $order2);
490490
$query->addOrder($order3);
491491
```
492492

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+
493527
## Getting the result
494528
That's the most easiest part:
495529

0 commit comments

Comments
 (0)