Skip to content

Commit 9811eb9

Browse files
committed
Adding sub-query documentation.
1 parent 4b64f55 commit 9811eb9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

doc/quickstart.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,50 @@ foreach ($userList as $user)
459459
}
460460
```
461461

462+
###Filtering by sub-query
463+
464+
`find` can also accept a result iterator (the result of a `find` method) as a filter.
465+
466+
```php
467+
class CountryDao extends AbstractCountryDao {
468+
/**
469+
* Returns the list of countries whose country name starts by "$countryName"
470+
*
471+
* @param string $countryName
472+
* @return Country[]
473+
*/
474+
public function findByCountryName($countryName) {
475+
return $this->find("name LIKE :country", [ 'country' => $countryName.'%' ] );
476+
}
477+
}
478+
479+
class UserDao extends AbstractUserDao {
480+
/**
481+
* @var TestCountryDao
482+
*/
483+
private $countryDao;
484+
485+
public function __construct(TDBMService $tdbmService, TestCountryDao $countryDao)
486+
{
487+
parent::__construct($tdbmService);
488+
$this->countryDao = $countryDao;
489+
}
490+
491+
/**
492+
* Returns the list of users whose country name starts by "$countryName"
493+
*
494+
* @param string $countryName
495+
* @return User[]
496+
*/
497+
public function getUsersByCountryName($countryName) {
498+
return $this->find($this->countryDao->findByCountryName($countryName));
499+
}
500+
}
501+
```
502+
503+
See? The `UserDao::getUsersByCountryName` method is making use of the `CountryDao::findByCountryName` method.
504+
It essentially says: "find all the users related to the result iterator of the countries starting with 'XXX'".
505+
462506
###Complex joins
463507

464508
![Users, roles and rights](images/user_role_right.png)

0 commit comments

Comments
 (0)