无法在非聚合查询中添加对未定义的结果变量的条件 [英] Cannot add having condition on undefined result variable in a non aggregated query
问题描述
我正在一个实体存储库中执行此查询,并继续获取
I'm executing this query in an entity repository and keep getting
无法添加对未定义的结果变量有条件
Cannot add having condition on undefined result variable
但查询根本没有聚合。为什么会发生这种情况?
but the query has no aggregation at all. Why is this happening to me?
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 trait,但仅在某些特定情况下,因此我不能使用全局可用的过滤器,必须手动实现。
PS: I have very little knowledge of Doctrine, i'm tasked to add soft delete support through KnpLabs SoftDeleteable trait but only in some specific situation, thus i can't use a globally available filter and must implement it manually.
推荐答案
DQL中有一个打字错误,该字段应该是ownerId而不是order_id。此外,需要提供每个字段的命名空间,如下所示:
There was a typo in the DQL, the field was supposed to be ownerId and not order_id. Further more, the the namespace of each field needs to be provided it seems such as:
public function getPersonalizableItemsByOwner(User $owner)
{
$qb = $this
->getEntityManager()
->createQuery('SELECT pi FROM '.$this->getEntityName().' pi WHERE pi.ownerId = :owner_id AND (pi.deletedAt IS NULL OR pi.deletedAt > :referenceDate)')
->setParameters(array('owner_id' => $owner->getId(), 'referenceDate' => date('Y-m-d H:i:s')));
return $qb->getResult();
}
这篇关于无法在非聚合查询中添加对未定义的结果变量的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!