寻求使用 Symfony 的 createQueryBuilder 复制此 SQL 查询:
Select * from user
left join location on location.id = user.id
where location.id is null
尝试过:
$er->createQueryBuilder('u')
->leftJoin('u.location','l')
->where('l.id = :id ')
->setParameter('id',null);
实体 - 用户、位置。用户与位置具有一对多关系。
QueryBuilder 生成 SQL
SELECT u0_.id AS id0, u0_.firstname AS firstname1, u0_.lastname AS lastname2, u0_.creationDate AS creationDate3
FROM User u0_
LEFT JOIN Locations l1_ ON u0_.id = l1_.user_id
WHERE l1_.id = ?
ORDER BY u0_.firstname AS
最佳答案
找到了解决方案。更改了检查 id
是否为空的方式。
$qBuilder = $er->createQueryBuilder('u')
->leftJoin('u.locations','l')
->where('l.id is NULL');
希望它能对某人有所帮助。
关于php - Symfony:与内连接查询相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30312731/