带有 OR 条件的原则 findBy
是否可以在 Doctrine findBy()
方法中使用 OR
语句? 我知道给定的数组被解释为 case1 AND case2...
就像
$this->repos['notif']->findBy(array('status' => 1, 'status' => 2, 'status' => 3);
现在代表
SELECT * FROM `notif` WHERE status=1 AND status=2 AND status=3;
我需要一些东西来代表:
SELECT * FROM `notif` WHERE status=1 OR status=2 OR status=3;
有没有办法获得所有案例?
Is it possible to use OR
statement in Doctrine findBy()
method?
I know that given array is interpreted as case1 AND case2...
Like this
$this->repos['notif']->findBy(array('status' => 1, 'status' => 2, 'status' => 3);
Stands for
SELECT * FROM `notif` WHERE status=1 AND status=2 AND status=3;
Now I need something to stand for:
SELECT * FROM `notif` WHERE status=1 OR status=2 OR status=3;
Is there a way to get all cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以写:
这也应该有效。
You can write:
and that should work too.
我知道这是老问题了。无论如何,可以使用
Criteria
进行复杂查询(至少在原则 2 中):I know that this is old question. Anyways, it's possible to use
Criteria
for the complex queries (in Doctrine 2 at least):据我所知,Doctrine 不支持将 IN() 查询与 findby 一起使用的功能。您可以做两件事:
在(自定义)“notif”存储库类中实现
findByStatus(array $statusTypes)
方法。如果您喜欢这种方法,我可以给您举一个例子。将您的 findBy 转换为以下内容:
这应该可以工作:)
As far as I know this is not a supported feature by Doctrine to use IN() queries with findby. You could do two things:
Implement a
findByStatus(array $statusTypes)
method in your (custom) 'notif' repository class. If you like this approach I can give you a example.Convert your findBy to the following:
That should work either :)
如果您正在使用 MongoDB 并且需要更复杂的查询,例如与 OR 链接在一起的“小于”,但无法使用查询生成器,这也适用于以下语法:
或者作为您问题的解决方案:
If you are using MongoDB and need more complex queries, like "less than" linked together with OR, but cannot use a query builder, this also works with this syntax:
Or as a solution for your question: