Wednesday, May 23, 2012

Translating SQL query to Doctrine2 DQL

I'm trying to translate this (My)SQL to DQL



SELECT content, created, AVG(rating)
FROM point
GROUP BY DAY(created)
ORDER BY created ASC


And I'm stuck at GROUP BY part, apparently DAY/WEEK/MONTH isn't recognized as valid "function".



[Semantical Error] line 0, col 80 near '(p.created) ORDER': Error: Cannot group by undefined identification variable.



$this->createQueryBuilder('p')
->select('p')
->groupBy('DAY(p.created)')
->orderBy('p.created', 'ASC')


Q: Is it possible to create this kind of query with query builder, or should I use native query?





No comments:

Post a Comment