Question: 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:

```php
public function findAllCounted()
{
    return $this->getEntityManager()
        ->createQuery('SELECT COUNT(a.id) FROM KSRArticleBundle:Article a')
        ->getSingleScalarResult();
}

```

Best Regards,
Bodo

Answer: 
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
SQL also allows this:

```
SELECT COUNT(1) FROM KSRArticleBundle:Article a

```

In this way the database does not even have to fetch any data from the table, which is even faster. Literally what it says: select the number of the constant '1' for every record. Small speed increase for well-designed data base servers and you dont have to remember anything about the table when writing this.