I got this Doctrine query:
select upper(substring(e.name, 1, 1)) first_letter
from Application\Models\Exercise e
group by first_letter
order by first_letter asc
But it throws an exception with the message:
Error: 'first_letter' does not point to a Class.
If I leave out the group by
and the order by
, it works.
Do I have to use a native query in this case or do the sorting and grouping in my client code (probably not such a good idea depending on the amount of data in the db...) or is it possible to get this query working?
Thanks!
EDIT:
This is my current approach, not so nice, but works for the moment as there is not much data in the db:
$tmpResult = $this->getEntityManager()->createQuery('
select upper(substring(e.name, 1, 1)) first_letter
from Application\Models\Exercise e
')->getResult();
$groupedAndSortedResult = array();
foreach($tmpResult as $row) {
$groupedAndSortedResult[$row['first_letter']] = $row['first_letter'];
}
sort($groupedAndSortedResult);
return array_values($groupedAndSortedResult);