我正在实体存储库中执行此查询并继续获取
Cannot add having condition on undefined result variable
但查询根本没有聚合.为什么会发生这种情况?
public function getPersonalizableItemsByOwner(User $owner) { $qb = $this ->getEntityManager() ->createQuery('SELECT pi FROM '.$this->getEntityName().' pi WHERE order_id = :owner_id AND (deletedAt IS NULL OR deletedAt > :referenceDate)') ->setParameters(array('owner_id' => $owner->getId(),'referenceDate' => date('Y-m-d H:i:s'))); return $qb->getResult(); }
PS:我对Doctrine知之甚少,我的任务是通过KnpLabs SoftDeleteable特性添加软删除支持,但仅限于某些特定情况,因此我不能使用全局可用的过滤器,必须手动实现.
您不能检查deletedAt是否为null,但检查deletedAt的ID是否为null.
更改为:deletedAt.id IS NULL应该修复它.
编辑:今天早上出现此错误,并修复它,谢谢:http://www.christophe-meneses.fr/article/corriger-l-erreur-request-critical-uncaught-php-exception-doctrine-orm-query-queryexception-semantical-error-cannot-add-having-condition-on-a-non-result-variable