原则:多个(whereIn OR whereIn)查询?
我在使用 Doctrine 制作一个相当简单的查询时遇到了麻烦...
我有两个数组($countries、$cities),我需要检查数据库记录值是否与其中任何一个数组匹配。我正在寻找类似的内容:
->whereIn('country', 'city', $countries, $cities)
...“国家”是 $countries 的 WHERE IN,“city”是 $city 的 WHERE IN。
我可以将两者分开,但所需的查询有很多其他条件,所以这是不可能的。我所追求的结果 SQL 是:
SELECT ...
WHERE ...
AND ...
AND ...
AND ('country' IN (1,2,3) OR 'city' IN (7,8,9))
AND ...
AND ...;
因此,人们也可以将其视为一个括号问题。有人知道 Doctrine DQL 是否可以实现这一点?我查看了文档但找不到任何方向。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一小时的实验,下面是让它发挥作用的语法。
After an hour of experimenting on this nonsense, here's the syntax to make it work.
为什么不使用类似的东西?
另外,将它们链接在一起以获取上下文(大多数 Doctrine 方法返回 $this)。
请参阅http://www.symfony-project.org/学说/1_2/en/06-处理数据
Why not use something like?
Also, chain them together for context (most Doctrine methods return $this).
see http://www.symfony-project.org/doctrine/1_2/en/06-Working-With-Data