Doctrine 2.0 NativeQuery ResultSetMapping for count(id)

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

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:

$rsm->addFieldResult('p', 'tot', 'tot');

as your column as been renamed with COUNT(id) AS tot. If remove the tot alias you can use your original code:

$rsm->addFieldResult('p', 'COUNT(id)', 'tot');

Need Your Help

How to set min-font-size in CSS

html5 css3 font-size

I want to set a minimum font size to every element in my HTML page.

Reading an Word file using NSTextStorage

ios nstextstorage

I thought I read in the documentation that NSTextStorage could read a Word file. I did this: