I have two Entity with a relation many to many (car and dealer). I have a working SQL request :
Select c.id, c.nom FROM car as c WHERE c.id NOT IN
(Select car_id FROM dealer_car where dealer_id = 16);
But with querybuilder I can't do this because dealer_car is the table of the many to many relation.
Actually I have this query Builder that return the exact oppose
'query_builder' => function(EntityRepository $er) use ($options){
return $er->createQueryBuilder('c')
->innerJoin('c.dealer','d')
->andWhere('c.id NOT IN (Select d.id FROM Bundle:Dealer de where de.id = :id)')
->setParameter('id',$options['data']->getId());
}
EDIT
I have the following data in my database
Car
1;BMW
2;Tesla
3;Mercedes
4;Toyota
dealer_car
16;2
16;3
dealer
1;Johnny
2;David
16;Nelson
And the result of the following Query is empty
select c.id, c.name,d.name from car c join dealer_car dc on c.car_id=c.id join dealer d on dc.d_id=d.id where d.id!=16