PressingOnAlways
PressingOnAlways

Reputation: 12356

Doctrine2 QueryBuilder HAVING max(field) IS NULL

How can I do the following with Doctrine2 QueryBuilder?

$qb->select('o, MAX(r.performanceDate) AS HIDDEN maxPerformanceDate')->
            from("Officer",'o')->
            leftJoin("o.reports",'r',Join::ON,'')->
            // andWhere('r.performanceDate is NULL OR maxPerformanceDate < :date OR maxPerformanceDate > :currentMonthDate')-> // does not work either, can't "WHERE" an aggregate function
            having('maxPerformanceDate < :date OR maxPerformanceDate > :currentMonthDate')->
            orHaving('maxPerformanceDate is null')-> // error here
            addOrderBy('r.performanceDate','ASC')->
            addOrderBy('o.name','ASC')->
            groupBy("o.id")
            // .. setParamters, etc.
        ;

When I execute the code, I get an error:

Doctrine\ORM\Query\QueryException : [Semantical Error] line 0, col 293 near 'maxPerformanceDate': Error: 'maxPerformanceDate' does not point to a Class.

I have tried this manually with MySQL and it works. Any workarounds appreciated. Preference is not to have to drop down to using native SQL.

The full table definition can be found in my other question:

SQL SELECT data between two related tables NOT within a certain date range

Upvotes: 1

Views: 752

Answers (1)

PressingOnAlways
PressingOnAlways

Reputation: 12356

This is a bug in Doctrine2. It has been fixed in the latest dev branch of doctrine, but won't be released until 2.5.

http://www.doctrine-project.org/jira/browse/DDC-1858

Upvotes: 1

Related Questions