2015-07-21 4 views
4

Я имею в хранилище этого кода:доктрина не существует подзапрос

public function getNotAssignedBy($speciality, $diploma) 
{ 
    $qb = $this->createQueryBuilder('j') 
     ->select('DISTINCT(j.id) id', 'j.firstName', 'j.lastName', 'j.dateBirth', 'j.sex') 
     ->leftJoin('j.qualifications', 'q') 
    ; 


    if ($speciality) { 
     $qb->andWhere('q.speciality = :speciality_id')->setParameter('speciality_id', $speciality); 
    } 
    if ($diploma) { 
     $qb->andWhere('q.diploma = :diploma_id')->setParameter('diploma_id', $diploma); 
    } 

    $result = $qb->getQuery()->getResult(); 

    return $result; 
} 

Как я могу получить только строки, в которых идентификатор не существует в других организациях ??

Любая помощь. Благодаря

ответ

13

Вы можете достичь его с чем-то вроде этого:

.... 
    // construct a subselect joined with an entity that have a relation with the first table as example user 
    $sub = $this->createQueryBuilder(); 
    $sub->select("t"); 
    $sub->from("AnotherEntity","t"); 
    $sub->andWhere('t.user = j.id'); 

    // Your query builder: 
    $qb->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL()))); 

Надежда эта помощь

+1

Спасибо Маттео. оно работает. –

Смежные вопросы