Strange problem when using HAVING() and Doctrine_Pager

橙三吉。 提交于 2020-01-03 03:04:07

问题


My program generates this DQL using echo $q->getDql(); reformated for easier reading:

SELECT o.*, t.*, COUNT(t.id) AS num_of_reservations 
FROM Property o 
LEFT JOIN o.Reservation t 
  WITH t.status=? AND 
 ( (t.start_date<=? AND t.end_date>=?) 
  OR (t.start_date>=? AND t.start_date <= ?) ) 

GROUP BY o.id 
HAVING num_of_reservations < o.nr_of_bookings

Using PHP unit tests, I get results as expected. However, when I send this Doctrine_Query to Doctrine_Pager, I get this error:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.nr_of_bookings' in 'having clause'

I tried all combinations like using having('COUNT(t.id)..... ) etc, different SELECT combos, all results picked by $q->execute() are good except when I send it to pager.

Can somebody help me with this? I even tried

FROM Property p 
instead of 
FROM Property o

no difference at all.

来源:https://stackoverflow.com/questions/4009158/strange-problem-when-using-having-and-doctrine-pager

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!