我从 NativeQuery 生成一个 SQL,这是结果 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);
这是我的结果集映射:
$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');
直接在mysql上运行上面的查询结果是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
但是结果数组 tot 别名不存在!!
问题是:
我如何为count(id)正确设置 ResultSetMapping ?