Is it possible to use OR statement in Doctrine findBy() method?
I want That the output Be like this :
SELECT * FROM `f
I would just use DQL... Add a function like this to your repository:
public function findFriends($userId)
{
return $this->getEntityManager()
->createQuery('SELECT f FROM Friends WHERE userId = :userId OR FriendId = :userId')
->setParameter('userId', $userId)
->getOneOrNullResult();
}
Or use the query builder instead of DQL:
public function findFriends($userId)
{
return $this->getEntityManager()
->createQueryBuilder()
->from('Friends', 'f')
->where('f.userId = :userId')
->orWhere('f.friendId = :userId')
->setParameter('userId', $userId)
->getQuery()
->getOneOrNullResult();
}
And then just use:
$user = $repository->findFriends($this->getRequest()->getSession()->get('id'));