Doctrine: Multiple (whereIn OR whereIn) query?

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-02-26T18:10:05Z Indexed on 2010/04/25 1:03 UTC
Read the original article Hit count: 353

Filed under:
|
|
|
|

I'm having trouble crafting a fairly simple query with Doctrine...

I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like:

->whereIn('country', 'city', $countries, $cities)

... with 'country' being a WHERE IN for $countries and 'city' being a WHERE IN for $city.

I could separate the two out but the needed query has lots of other conditions so that's not possible. The resulting SQL I'm after would be:

SELECT ... 
WHERE ... 
AND ...
AND ... 
AND ('country' IN (1,2,3) OR 'city' IN (7,8,9))
AND ... 
AND ...;

One could therefore think of it also as a bracketing issue only. Anyone know if this is possible with Doctrine DQL? I've looked through the documentation but can't find any direction.

Thanks

© Stack Overflow or respective owner

Related posts about doctrine

Related posts about symfony