1

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

Community
  • 1
  • 1
PressingOnAlways
  • 11,948
  • 6
  • 32
  • 59
  • ahh you deleted that quickly, but here : `echo json_encode($test, true);` – meda Apr 18 '14 at 06:32
  • @meda, wrong question, and i deleted it because the question was wrong. I was getting [] array objects because I ran it through a sort that was changing my keys into numeric array values. It had nothing to do with what I thought it was. – PressingOnAlways Apr 18 '14 at 07:21

1 Answers1

1

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

PressingOnAlways
  • 11,948
  • 6
  • 32
  • 59