教条找ORB条件 [英] Doctrine findBy with OR condition
问题描述
可以在Doctrine findBy()
方法中使用 OR
语句吗?
我知道给定的数组解释为 case1 AND case2 ...
像这样
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);
代表
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?
推荐答案
据了解,Doctrine不支持使用与findby进行IN()查询的功能,您可以做两件事情: / p>
As far as I know this is not a supported feature by Doctrine to use IN() queries with findby. You could do two things:
-
在(自定义)中实现一个
findByStatus(array $ statusTypes)
)'notif'存储库类如果你喜欢这种方法,我可以给你一个例子。
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:
$qb = $this->repos['notif']->createQueryBuilder('n');
$data = $qb->where($qb->expr()->in('status', array(1,2,3)))->getQuery()->getResult();
这应该是:)
这篇关于教条找ORB条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!