Doctrine2: Filtering by ManToMany Association
Posted
by
Shroder
on Stack Overflow
See other posts from Stack Overflow
or by Shroder
Published on 2012-12-09T16:21:54Z
Indexed on
2012/12/11
5:04 UTC
Read the original article
Hit count: 163
I want to retrieve a collection of objects based on what they are associated to. For example, by a category. This would be a Many to Many relationship.
I've been able to achieve that with MEMBER OF, however I need to pass in an array of IDs, opposed to one at a time. I see there is an "IN ()", but it seems to require a subquery, which I would like to avoid.
MEMBER OF example:
SELECT o FROM Entity\Object1 o WHERE 'CATEGORY_CODE' MEMBER OF o.categories
(Edit)
This is what I would like to do, but perhaps I'm misunderstanding how entities work in DQL:
SELECT o FROM Entity\Object1 o WHERE o.categories.Id IN (id, id, id)
© Stack Overflow or respective owner