在查询生成器中左连接外部查询

时间:2016-08-05 11:06:27

标签: symfony query-builder

我需要在查询构建器

中创建该查询
SELECT * FROM table1 LEFT JOIN table2 ON (table1.parent_id = table2.id OR table1.id = table2.id) WHERE table2.id IS NULL;

我已经

$er->createQueryBuilder('p')
                    ->leftJoin('Bundle2:table2', 'n')
                    ->where('p.parent = n.id')
                    ->andWhere('p.id = n.id');

但不知道如何添加外部WHERE来查询?

1 个答案:

答案 0 :(得分:0)

试试这个:

return $this->createQueryBuilder('t1')
      ->leftJoin('t1.table2', 't2')
      ->where('t1.parent = t2.id OR t1.id = t2.id')
      ->andWhere('t2.id IS NULL')
      ->getQuery()
      ->getResult();
相关问题