symfony - How to use leftJoin and Join in table association in createQuery
習慣沉默
習慣沉默 2017-05-16 16:44:41
0
1
514

The relationship between the three tables

a oneToMany b
b oneToMany c

Purpose: I want to find all a data without c data
Example: Police Officer Li (a) has three guns (b) each gun has bullets (c)
What I want to find is the policeman without bullets. Add the three guns of Police Wang, two of them have no bullets, but if one gun has bullets, do not select him. I want to find the policeman without any bullets.

So I wrote the following code

$em = $this->getDoctrine()->getManager();
        $qb = $em->createQueryBuilder();
        $qb->select('a', 'b')
                ->from('aaBundle:a', 'a')
                ->leftJoin('a.b', 'b')
                ->leftJoin('b.c', 'c')
                ->where('c.id is null');
        $query = $qb->getQuery();
        $result = $query->getArrayResult();

But they found Police Wang, the policeman with a bullet in his gun.
How to modify this code.

習慣沉默
習慣沉默

reply all(1)
黄舟

First look for the gun without bullets, then look for the ID of the gun (the policeman with bullets), then NOT IN

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template