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)
459
459
}
460
460
```
461
461
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
+
462
506
###Complex joins
463
507
464
508
![ Users, roles and rights] ( images/user_role_right.png )
You can’t perform that action at this time.
0 commit comments