I would like to know how I can count all records of an entity in a doctrine repository
I found this solution but am not sure if this is good so:
public function findAllCounted()
{
return $this->getEntityManager()
->createQuery('SELECT COUNT(a.id) FROM KSRArticleBundle:Article a')
->getSingleScalarResult();
}
Best Regards, Bodo
You don't need to count on a specific field, so this will do:
SELECT COUNT(a) FROM KSRArticleBundle:Article a
Just for the record, it is usually better to count on the id :
SELECT COUNT(a.id) FROM KSRArticleBundle:Article a
is a little better
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With