|
37 | 37 | echo "{$customer->first_name} {$customer->last_name}, {$customer->job_title}\n";
|
38 | 38 | }
|
39 | 39 |
|
40 |
| -$customerTable->addOrderBy('last_name'); |
| 40 | +$customerTable->setOrderBy('last_name'); |
41 | 41 | echo "\n\nCustomers in last_name order:\n\n";
|
42 | 42 | foreach ($customerTable->getRecordCursor() as $customer)
|
43 | 43 | {
|
44 | 44 | echo "{$customer->first_name} {$customer->last_name}, {$customer->job_title}\n";
|
45 | 45 | }
|
46 | 46 |
|
47 |
| -$customerTable->addOrderBy('last_name', 'desc'); |
| 47 | +$customerTable->setOrderBy('last_name', 'desc'); |
48 | 48 | $customerTable->setLimit(10);
|
49 | 49 |
|
50 |
| -echo "\n\nLast 10 Customers in last_name order:\n\n"; |
| 50 | +echo "\n\nLast 10 Customers in last_name order descending:\n\n"; |
51 | 51 | foreach ($customerTable->getRecordCursor() as $customer)
|
52 | 52 | {
|
53 | 53 | echo "{$customer->first_name} {$customer->last_name}, {$customer->job_title}\n";
|
54 | 54 | }
|
55 | 55 |
|
56 |
| -$customerTable->setLimit(0); |
57 |
| -$customerTable->addGroupBy('company'); |
58 |
| -$customerTable->addSelect(new \PHPFUI\ORM\Literal('count(*)'), 'count'); |
59 |
| -$customerTable->addSelect('company'); |
60 |
| -$customerTable->setOrderBy('company'); |
61 |
| -echo "\n\nCount of Customers by company:\n\n"; |
| 56 | +$orderTable = new \Tests\App\Table\Order(); |
| 57 | +$orderTable->addJoin('customer'); |
| 58 | +$orderTable->addGroupBy('customer.customer_id'); |
| 59 | +$orderTable->addSelect(new \PHPFUI\ORM\Literal('count("order_id")'), 'count'); |
| 60 | +$orderTable->addSelect('company'); |
| 61 | +$orderTable->setOrderBy('company'); |
| 62 | +echo "\n\nCount of Orders by customer:\n\n"; |
62 | 63 |
|
63 |
| -foreach ($customerTable->getDataObjectCursor() as $customer) |
| 64 | +foreach ($orderTable->getDataObjectCursor() as $customer) |
64 | 65 | {
|
65 | 66 | echo "{$customer->company}: {$customer->count}\n";
|
66 | 67 | }
|
67 | 68 |
|
68 |
| - |
69 | 69 | $orderTable = new \Tests\App\Table\Order();
|
70 | 70 | // addJoin defaults to using the primary key of the related table
|
71 | 71 | $orderTable->addJoin('customer');
|
|
0 commit comments