From 2e2b1cb4ac93b20eacc815f6e90e0bcf0873a371 Mon Sep 17 00:00:00 2001 From: "Vladislav O. Vlastovskiy" Date: Thu, 2 Aug 2012 12:45:36 +0400 Subject: [PATCH] Fixed an incorrect calculation COUNT Fixed an incorrect calculation of the number of objects, using JOIN. --- Adapter/DoctrineOrmAdapter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Adapter/DoctrineOrmAdapter.php b/Adapter/DoctrineOrmAdapter.php index 3d0bebf..a1f9ec7 100644 --- a/Adapter/DoctrineOrmAdapter.php +++ b/Adapter/DoctrineOrmAdapter.php @@ -42,7 +42,12 @@ public function getCountQuery() $qb = clone $this->query; - return $qb->select('COUNT(' . $a . ')')->resetDQLPart('orderBy')->setMaxResults(null)->setFirstResult(null); + return $qb + ->select($qb->getDQLPart('distinct') ? $qb->expr()->countDistinct($a) : $qb->expr()->count($a)) + ->resetDQLParts(array('orderBy', 'distinct')) + ->setMaxResults(null) + ->setFirstResult(null) + ; } /**