currently i am trying to build another Query into the Kohana ORM. This is my SQL Statement (works fine for me)
SELECT needle, COUNT(needle) FROM my.haystacks GROUP BY needle ORDER BY COUNT(needle) DESC;
In Kohana it's the following snippet:
$needleCount = ORM::factory('haystack')->select(array('needle'))->group_by('needle')->order_by('COUNT("needle")', 'DESC')->find_all()->as_array();
Looks good? Following exception returns:
Unknown column 'COUNT("needle")'
[ SELECT `needle` AS `needle` FROM `haystacks` AS `haystack` GROUP BY `needle` ORDER BY `COUNT("needle")` DESC ]
So, Kohana is trying to SELECT the COUNT("needle") as a column. Any ideas to fix this?