Doctrine 2.1 DQL - Many-to-many query multiple values - Item in multiple categories? Doctrine 2.1 DQL - Many-to-many query multiple values - Item in multiple categories? sql sql

Doctrine 2.1 DQL - Many-to-many query multiple values - Item in multiple categories?


For anyone interested, I figured it out (painfully). Doctrine should really explain this better instead of the the one line they have on the DQL page....

Basically it's not an AND query, it's a MEMBER OF AND query. For each category a MEMBER OF must be created and then added to the whole query with an AND:

SELECT j, t FROM Entity\Item j LEFT JOIN j.itemImages t WHERE ?0 MEMBER OF j.categories AND ?1 MEMBER OF j.categories AND ?2 MEMBER OF j.categories, etc.

That will return all items that are in all categories requested.