Piotr Synowiec
Piotr Synowiec
~1 min read

Categories

Tags

Counting entities the fastest way (at least the fastest way I found)

function countEntities(EntityManagerInterface $em, string $className): int
{
    return current($em->createQueryBuilder()
        ->select('count(c.id)')
        ->from($className, 'c')
        ->getQuery()
        ->getSingleResult());
}