学说:多个(whereIn OR whereIn)查询? [英] Doctrine: Multiple (whereIn OR whereIn) query?

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

问题描述

我在用 Doctrine 编写一个相当简单的查询时遇到了麻烦...

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

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

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)

... 'country' 是 $countries 的 WHERE IN,而 'city' 是 $city 的 WHERE IN.

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

我可以将两者分开,但所需的查询有很多其他条件,所以这是不可能的.我所追求的结果 SQL 将是:

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 ...;

因此,人们也可以将其仅视为一个括号问题.任何人都知道这是否可以通过 Doctrine DQL 实现?我浏览了文档,但找不到任何方向.

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.

谢谢

推荐答案

在对这个废话进行了一个小时的试验之后,下面是使它起作用的语法.

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)));

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

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