Doctrine:Multiple(whereIn OR whereIn)查询? [英] Doctrine: Multiple (whereIn OR whereIn) query?

查看:148
本文介绍了Doctrine:Multiple(whereIn OR whereIn)查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦用Doctrine制作一个相当简单的查询...



我有两个数组($ countries,$ cities),我需要检查数据库记录值将匹配任何一个。我正在寻找类似的东西:

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

...国家为$国家的WHERE IN,城市为WHERE IN for $ city。



我可以将两个分开,但是所需的查询有很多其他条件,所以这是不可能的。我之后产生的SQL将是:

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

因此,人们可以将其视为包围问题。任何人都知道这是否可以用Doctrine DQL?我看过文档,但找不到任何方向。



谢谢

解决方案

经过一个小时的实验,这个废话,这里是使其工作的语法。

  $ q- > andWhere('country IN?OR city IN?',array(array(1,2,3),array(7,8,9))); 


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

解决方案

After an hour of experimenting on this nonsense, here's the syntax to make it work.

$q->andWhere('country IN ? OR city IN ?', array(array(1, 2, 3), array(7, 8, 9)));

这篇关于Doctrine:Multiple(whereIn OR whereIn)查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆