2014-02-27 53 views
1

如何使用Doctrine2 QueryBuilder執行以下操作?Doctrine2 QueryBuilder HAVING max(field)IS NULL

$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. 
     ; 

當我執行的代碼,我得到一個錯誤:

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

我已經與MySQL手動嘗試這樣做,它的工作原理。任何解決方法讚賞。首選項不必下降到使用本機SQL。

全表定義可以在我的其他問題可以找到:

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

+0

啊你刪除的很快,但在這裏:'回聲json_encode($測試,真正的);' – meda

+0

@meda,錯的問題,我刪除了它,因爲這個問題是錯誤的。我得到[]數組對象,因爲我通過一種將我的鍵更改爲數字數組值的排序方式來運行它。它與我以爲是無關的。 – PressingOnAlways

回答