I generate an SQL from NativeQuery and this is the result sql:
SELECT COUNT(id) AS tot,created_at FROM property WHERE created_at
BETWEEN ‘20120501000000’ AND ‘20120521235959’ GROUP BY
YEAR(created_at),MONTH(created_at),DAY(created_at);
This is my ResultSetMapping:
$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('Entity\Property', 'p');
$rsm->addFieldResult('p','count(id)','tot'); // <-- this don't work
$rsm->addFieldResult('p','created_at','created_at');
The result running the above query direct on mysql is ok:
tot created_at
11 2012-05-02 11:23:25
11 2012-05-08 14:56:40
152 2012-05-16 14:43:46
5 2012-05-17 16:26:31
29 2012-05-18 14:55:33
But the result array the tot alias don’t exist!!
The Question is:
How i set ResultSetMapping correctly for count(id)?
I would try:
as your column as been renamed with
COUNT(id) AS tot. If remove thetotalias you can use your original code: