$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder();
$tickets = $qb->select('COUNT(ticket.id)')->from('MyBundle:Ticket', 'ticket');
var_dump($tickets->getQuery()->getSingleScalarResult());
返回
array(1) {
[0]=>
array(1) {
[1]=>
string(3) "125"
}
}
但在数据库中只有 5 个条目。有什么想法有什么问题吗?
var_dump($tickets->getQuery()->getSql());
给
SELECT COUNT(t0_.id) AS sclr0 FROM ticket t1_, ticket t2_, ticket t0_ GROUP BY t0_.id ORDER BY t2_.created_at ASC LIMIT 1