Skip to content

Commit 2aff707

Browse files
committed
Fix new usage
1 parent ba85b0e commit 2aff707

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class `Restrictions` is there to create them:
440440
```
441441
$expr1 = Restrictions::eq('name', 'myUsername');
442442
$expr2 = Restrictions::isNotNull('email');
443-
$query->add($expr1, $expr);
443+
$query->where($expr1, $expr);
444444
```
445445

446446
The most common restrictions are provided: eq, ne, lt, gt, ge, le, like, isNull, isNotNull, between. You can also
@@ -484,8 +484,8 @@ $order2 = \TgDatabase\Order::desc(array('b', 'columnFromJoinedTable'));
484484
Finally add these objects to your query:
485485

486486
```
487-
$query->addOrder($order1, $order2);
488-
$query->addOrder($order3);
487+
$query->orderBy($order1, $order2);
488+
$query->orderBy($order3);
489489
```
490490

491491
## Modifying the column list: columns and projections
@@ -494,33 +494,33 @@ the column list:
494494

495495
```
496496
// Select myColumn only
497-
$query->addColumn(Projections::property('myColumn'));
497+
$query->select(Projections::property('myColumn'));
498498
499499
// Add another column
500-
$query->addColumn(Projections::property('anotherColumn'));
500+
$query->select(Projections::property('anotherColumn'));
501501
```
502502

503-
Please notice that the first call to `addColumn` will remove the `*` retrieval
503+
Please notice that the first call to `select` will remove the `*` retrieval
504504
on the query. Any subsequent call will enhance the list. The same result can be
505505
achieved with:
506506

507507
```
508-
$query->setColumns(Projections::property('myColumn'), Projections::property('anotherColumn'));
508+
$query->setSelect(Projections::property('myColumn'), Projections::property('anotherColumn'));
509509
```
510510

511511
And there are some shortcuts:
512512

513513
```
514514
// Variant 1: flexible argument list
515-
$query1->addColumn(Projections::property('myColumn'), Projections::property('anotherColumn'));
515+
$query1->select(Projections::property('myColumn'), Projections::property('anotherColumn'));
516516
517517
// Variant 2: use #properties() method in Projections
518-
$query1->addColumn(Projections::properties('myColumn', 'anotherColumn'));
518+
$query1->select(Projections::properties('myColumn', 'anotherColumn'));
519519
```
520520

521-
**Attention:** A call to `setColumns()` or `setProjection()` (deprecated alternative) will always remove
522-
the result class definition in the query object. This will ensure compatibility with previous versions.
523-
So you would need to call `setResultClass()` in case you want the query to return other classes than `stdClass`.
521+
**Attention:** A call to `setSelect()` or `setProjection()` (deprecated alternative) will NOT remove
522+
the result class definition in the query object as done before. This will breaks compatibility with previous versions.
523+
So you need to call `setResultClass(NULL)` to have `stdClass` returned.
524524

525525
## Getting the result
526526
That's the most easiest part:
@@ -547,11 +547,12 @@ Basic projections - the aggregation of columns of different rows - are available
547547

548548
```
549549
$proj = Projections::rowCount();
550-
$query->setProjection($proj);
550+
$query->setlect($proj);
551551
```
552552

553553
You will find projections for: count, distinct, sum, avg, min, max. Please notice that
554-
the returned model class is always the `stdClass` when using projections.
554+
the returned model class is not reset. You need to call `setResultClass(NULL) to have
555+
`stdClass` returned when using projections.
555556

556557
## Subqueries and JOINs
557558
This is most likely the biggest advance in using the Query API. The traditional API methods
@@ -570,21 +571,21 @@ to join them properly:
570571
```
571572
$authors = $authorDAO->createQuery('b');
572573
$restriction = Restrictions::eq(array('a','author'), array('b','uid'));
573-
$query->addJoinedQuery($authors, $restriction);
574+
$query->join($authors, $restriction);
574575
```
575576

576577
And finally we apply the search condition for the author:
577578

578579
```
579-
$authors->add(Restrictions::like('name', 'A%'));
580+
$authors->where(Restrictions::like('name', 'A%'));
580581
```
581582

582583
Another way of adding subqueries is directly via the main `Query` object:
583584

584585
```
585586
$authors = $booksDAO->createQuery('a');
586-
$authors->createJoinedQuery('#__authors', 'b', Restrictions::eq(array('a','author'), array('b','uid')));
587-
$authors->add(Restrictions::like('name', 'A%'));
587+
$authors->createJoin('#__authors', 'b', Restrictions::eq(array('a','author'), array('b','uid')));
588+
$authors->where(Restrictions::like('name', 'A%'));
588589
```
589590

590591
## Updating and deleting multiple objects
@@ -594,11 +595,11 @@ The `Query` object can also update and delete objects:
594595
// Update
595596
$restrictions = Restrictions::eq('name', 'John Doe');
596597
$updates = array('comment' => 'This is an unknown author');
597-
$dao->createQuery()->add($restrictions)->update($updates);
598+
$dao->createQuery()->where($restrictions)->update($updates);
598599
599600
// Delete
600601
$restrictions = Restrictions::eq('name', 'Jane Doe');
601-
$dao->createQuery()->add($restrictions)->delete();
602+
$dao->createQuery()->where($restrictions)->delete();
602603
```
603604

604605
## GROUP BY and HAVING clauses
@@ -607,9 +608,10 @@ The Query API allows to define grouping result sets and restricting the returned
607608
```
608609
// List the number of books that authors published whose names begin with 'John'
609610
$bookQuery
610-
->setColumns(Projections::property('author'), Projections::rowCount('cnt'))
611+
->select(Projections::property('author'), Projections::rowCount('cnt'))
611612
->groupBy(Projections::property('author'))
612613
->having(Restrictions::like('author', 'John%'))
614+
->setResultClass(NULL)
613615
->list();
614616
```
615617

src/TgDatabase/Criterion/QueryImpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function list($throwException = FALSE) {
205205
* Count the results.
206206
*/
207207
public function count($throwException = FALSE) {
208-
$query = $this->clone()->setProjection(Projections::alias(Projections::rowCount(), 'cnt'))->setResultClass(NULL);
208+
$query = $this->clone()->select(Projections::alias(Projections::rowCount(), 'cnt'))->setResultClass(NULL);
209209
$record = $query->first();
210210
if ($query->hasError()) {
211211
if ($throwException) {

0 commit comments

Comments
 (0)