[英]Doctrine2 QueryBuilder: How to filter out entities having zero count for a OneToMany
In my Dymfony2 / Doctrine2 application, I have a oneToMany relation between an object and its children. 在我的Dymfony2 / Doctrine2应用程序中,我在对象及其子对象之间有一个oneToMany关系。
I want to select all objects which have no children. 我想选择所有没有孩子的物品。
I'm stuck with various errors: SingleValuedAssociationField expected, Cannot add Having sth on non result variable , etc. 我遇到了各种错误: 期望SingleValuedAssociationField,无法添加非结果变量等等。
$queryBuilder = $this
->createQueryBuilder('object')
->leftJoin('object.children', 'children')
->andWhere('children IS NULL')
// tested with a parameter, with addselect COUNT(children) and 0 condition, etc.
->getQuery()
->getResult();
How can I solve this? 我怎么解决这个问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.