Is it possible to use OR statement in Doctrine findBy() method?
I want That the output Be like this :
SELECT * FROM `friends` WHERE userId=1 OR FriendId=1 ;
The code Now :
$user = $repository->findBy(array(
'userId' => $this->getRequest()->getSession()->get('id')
);
MongoDB specific syntax
You can use the
$or
and$and
keys in the array you pass tofindBy
:Using QueryBuilder:
But seeing as this is mongoDB specific, this probably doesn't answer your question. Using the queryBuilder, you could just write this:
You could build the
or
clause using querybuilder expressions instead, that would look something like this:Here's some more info
Even though you're using the same value twice, you have to call
setParameter
twice. The reason for this can be found hereLastly, some more docs on the
QueryBuilder
classI would just use DQL... Add a function like this to your repository:
Or use the query builder instead of DQL:
And then just use: