File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments