Doctrine findBy with OR condition
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?
You can write:
$this->repos['notif']->findBy(array('status' => array(1, 2, 3)));
and that should work too.
I know that this is old question. Anyways, it's possible to use Criteria
for the complex queries (in Doctrine 2 at least):
$criteria = new \Doctrine\Common\Collections\Criteria();
$criteria
->orWhere($criteria->expr()->contains('domains', 'a'))
->orWhere($criteria->expr()->contains('domains', 'b'));
$groups = $em
->getRepository('Group')
->matching($criteria);