Short and Simple: From time to time we send gifts to some of our users. I have a user
table and a gift
table with a many-to-many relationship. I want to fetch all users which did NOT receive a particular gift.
The following query however returns me all users and the gifts they've received, with the particular gift excluded.
$qb = $this->_em->createQueryBuilder();
$qb->select('u, g')
->from('Application\Entity\User', 'u')
->leftJoin('u.gifts', 'g')
->where('g.id != = :giftId')
->setParameter('giftId', 2);
If a user received a particular gift, I want to exclude that user from the result set. Is this possible with Doctrine2?