'QueryBuilder a ManyToMany to find all not in the jointable in Doctrine

I have a ManyToMany relation in Doctrine, I created entities for table A and table B and Doctrine created a junction table C.

I'm trying to bring all results from table B that have no realtionship in table C.

Have tried many approaches but no success, about to remake this as a ManyToOne as last restor...

So far have tried using "MEMBER OF", native SQL, DQL, no success, can someone teach me how it works when querying when tables have attributes collection and not columns?

$query = $qb->select('a')
                ->innerJoin('a.clusters', 'c', Join::WITH, 'a.id = c.id')
                ->getQuery();

Return zero results :/



Solution 1:[1]

you can use this:

$query = $qb->select('b')
        ->leftJoin('b.c', 'c')
        ->where('c.id != b.id')
         ->getQuery();

Solution 2:[2]

Thanks to Sadegh Rohani insight, I was able to find the answer

$qb->select('a')
   ->leftJoin('a.c', 'c')
   ->where('c.id is null');

This querybuilder will find all entities a that do not belong to any c, which in manytomany relation is an arrayCollection attribute inside 'a' entity.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sadegh Rohani
Solution 2 guilherme.souza