1

i created a query using query builder and now i want to get how many records are in the result but from some reason it throws me NonUniqueResultException

Here is the code

    $VideoQueueRepo = $this->_EntityManager->getRepository("TestTestAppBundle:VideoQueue");
    $VideoQueue  = $VideoQueueRepo->createQueryBuilder('VQ')
                                     ->where("VQ.reviewStatus = :ReviewStatus")
                                     ->setParameter('ReviewStatus', VideoConstants::STATUS_NEW)
                                     ->getQuery();
    $VideoQueueCount = $VideoQueue->getSingleScalarResult();

And i cant do this count($VideoQueue->getResult()); because there are around 50 000 records in result and every request for that gets canceled and i get this in symfony log

 emergency.EMERGENCY: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)

How do i get count of records in result?

1 Answers1

1

The NonUniqueResultException is thrown if your query results in more than one row. If you have many video queues with status new, this is the case.

To count your items with status new write

$VideoQueue = $VideoQueueRepo->createQueryBuilder('VQ')
                             ->select('COUNT(VQ)')
                             ->where("VQ.reviewStatus = :ReviewStatus")
                             ->setParameter('ReviewStatus', VideoConstants::STATUS_NEW)
                             ->getQuery();
SBH
  • 1,787
  • 3
  • 22
  • 27