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?
I know that this is old question. Anyways, it's possible to use
Criteria
for the complex queries (in Doctrine 2 at least):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:
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 :)
You can write:
and that should work too.