Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: 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.

like image 860
Mathieu Dumoulin Avatar asked May 21 '15 15:05

Mathieu Dumoulin


1 Answers

You must not check for deletedAt to be null but the check if deletedAt's ID to be null.

Changing to : deletedAt.id IS NULL should fix it.

edit : Got this error this morning and fixed it thanks to : 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

like image 175
arnaudbey Avatar answered Nov 15 '22 19:11

arnaudbey