diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php index c293d356..6a60d085 100644 --- a/src/Repository/ActivityRepository.php +++ b/src/Repository/ActivityRepository.php @@ -261,7 +261,6 @@ class ActivityRepository extends EntityRepository $qb ->select('a') - ->distinct() ->from(Activity::class, 'a') ->leftJoin('a.project', 'p') ->leftJoin('p.customer', 'c') @@ -362,6 +361,13 @@ class ActivityRepository extends EntityRepository } } + // this will make sure, that we do not accidentally create results with multiple rows, + // which would result in a wrong LIMIT with paginated results + $qb->addGroupBy('a'); + + // the second group by is needed to satisfy SQL standard (ONLY_FULL_GROUP_BY) + $qb->addGroupBy($orderBy); + return $qb; } diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index d2866710..ce746505 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -105,7 +105,7 @@ class CustomerRepository extends EntityRepository $qb = $this->getEntityManager()->createQueryBuilder(); $qb - ->addSelect('COUNT(a.id) as activityAmount') + ->select('COUNT(a.id) as activityAmount') ->from(Activity::class, 'a') ->join(Project::class, 'p', Query\Expr\Join::WITH, 'a.project = p.id') ->andWhere('a.project = p.id') @@ -118,7 +118,7 @@ class CustomerRepository extends EntityRepository } $qb = $this->getEntityManager()->createQueryBuilder(); - $qb->addSelect('COUNT(p.id) as projectAmount') + $qb->select('COUNT(p.id) as projectAmount') ->from(Project::class, 'p') ->andWhere('p.customer = :customer') ; @@ -165,7 +165,7 @@ class CustomerRepository extends EntityRepository } /** - * @deprecated since 1.1 - use getQueryBuilderForFormType() istead - will be removed with 2.0 + * @deprecated since 1.1 - use getQueryBuilderForFormType() instead - will be removed with 2.0 */ public function builderForEntityType($customer) { @@ -214,12 +214,10 @@ class CustomerRepository extends EntityRepository $qb ->select('c') - ->distinct() ->from(Customer::class, 'c') ; - $orderBy = 'c.' . $query->getOrderBy(); - $qb->orderBy($orderBy, $query->getOrder()); + $qb->orderBy('c.' . $query->getOrderBy(), $query->getOrder()); if ($query->isShowVisible()) { $qb->andWhere($qb->expr()->eq('c.visible', ':visible')); @@ -269,6 +267,10 @@ class CustomerRepository extends EntityRepository } } + // this will make sure, that we do not accidentally create results with multiple rows, + // which would result in a wrong LIMIT with paginated results + $qb->addGroupBy('c'); + return $qb; } diff --git a/src/Repository/InvoiceRepository.php b/src/Repository/InvoiceRepository.php index 9ce5c10b..4b097c09 100644 --- a/src/Repository/InvoiceRepository.php +++ b/src/Repository/InvoiceRepository.php @@ -137,7 +137,6 @@ class InvoiceRepository extends EntityRepository $qb ->select('i') - ->distinct() ->from(Invoice::class, 'i') ; @@ -152,6 +151,13 @@ class InvoiceRepository extends EntityRepository $this->addPermissionCriteria($qb, $query->getCurrentUser()); + // this will make sure, that we do not accidentally create results with multiple rows, + // which would result in a wrong LIMIT with paginated results + $qb->addGroupBy('i'); + + // the second group by is needed to satisfy SQL standard (ONLY_FULL_GROUP_BY) + $qb->addGroupBy($orderBy); + return $qb; } diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index d6d3ff0c..828d6ac2 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -255,7 +255,6 @@ class ProjectRepository extends EntityRepository $qb ->select('p') - ->distinct() ->from(Project::class, 'p') ->leftJoin('p.customer', 'c') ; @@ -367,6 +366,13 @@ class ProjectRepository extends EntityRepository } } + // this will make sure, that we do not accidentally create results with multiple rows, + // which would result in a wrong LIMIT with paginated results + $qb->addGroupBy('p'); + + // the second group by is needed to satisfy SQL standard (ONLY_FULL_GROUP_BY) + $qb->addGroupBy($orderBy); + return $qb; }