If you mean that your property (through which you wanted to filter) is not directly defined on the items you are filtering, then Criteria is not sufficient. In order to filter data through different associations, you either iterate and run checks, or you use callback criteria expressions (not lazy, not happening at SQL level) or you use DQL in a custom repository.
Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 30 March 2014 11:02, Gerard Brouwer <[email protected]> wrote: > Marco, > > Thanks, this seems to work. I saw something about filtering but I assumed > it was applied after fetching the data. > > Ok, what if the Profile is of a Network, which needs to be active too in > this case (withing getActiveProfiles method of Account)? > > Gerard > > > Op zaterdag 29 maart 2014 00:07:07 UTC+1 schreef Marco Pivetta: >> >> You can filter collections via the criteria api: >> >> public function getActiveProfiles() >> { >> $criteria = new \Doctrine\Common\Collections\Criteria(); >> $criteria->andWhere($criteria->expr()->eq('active', true); >> >> return $this->profiles->matching($criteria); >> } >> >> See also http://doctrine-orm.readthedocs.org/en/latest/ >> reference/working-with-associations.html#filtering-collections >> >> Marco Pivetta >> >> http://twitter.com/Ocramius >> >> http://ocramius.github.com/ >> >> >> On 28 March 2014 22:48, Gerard Brouwer <[email protected]> wrote: >> >>> Hi, >>> >>> >>> I'm starting with Doctrine 2 + Zend Framework 2. >>> I have an Entity Account which has a OneToMany relationship to Profile. >>> If I call getProfiles on Account, I only want Profile instances with the >>> column 'active' = 'yes'. Of course, I want it to call on the Account Entity >>> instance (getProfiles() or getActiveProfiles()). >>> >>> How to do this in the best way? I didn't find a solution for this (no >>> annotations, no possibility to access the QueryBuilder within the entity). >>> >>> Gerard >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "doctrine-user" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> >>> Visit this group at http://groups.google.com/group/doctrine-user. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
