fix distinct vs group_by (#1901)
This commit is contained in:
@@ -261,7 +261,6 @@ class ActivityRepository extends EntityRepository
|
|||||||
|
|
||||||
$qb
|
$qb
|
||||||
->select('a')
|
->select('a')
|
||||||
->distinct()
|
|
||||||
->from(Activity::class, 'a')
|
->from(Activity::class, 'a')
|
||||||
->leftJoin('a.project', 'p')
|
->leftJoin('a.project', 'p')
|
||||||
->leftJoin('p.customer', 'c')
|
->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;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class CustomerRepository extends EntityRepository
|
|||||||
|
|
||||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||||
$qb
|
$qb
|
||||||
->addSelect('COUNT(a.id) as activityAmount')
|
->select('COUNT(a.id) as activityAmount')
|
||||||
->from(Activity::class, 'a')
|
->from(Activity::class, 'a')
|
||||||
->join(Project::class, 'p', Query\Expr\Join::WITH, 'a.project = p.id')
|
->join(Project::class, 'p', Query\Expr\Join::WITH, 'a.project = p.id')
|
||||||
->andWhere('a.project = p.id')
|
->andWhere('a.project = p.id')
|
||||||
@@ -118,7 +118,7 @@ class CustomerRepository extends EntityRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||||
$qb->addSelect('COUNT(p.id) as projectAmount')
|
$qb->select('COUNT(p.id) as projectAmount')
|
||||||
->from(Project::class, 'p')
|
->from(Project::class, 'p')
|
||||||
->andWhere('p.customer = :customer')
|
->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)
|
public function builderForEntityType($customer)
|
||||||
{
|
{
|
||||||
@@ -214,12 +214,10 @@ class CustomerRepository extends EntityRepository
|
|||||||
|
|
||||||
$qb
|
$qb
|
||||||
->select('c')
|
->select('c')
|
||||||
->distinct()
|
|
||||||
->from(Customer::class, 'c')
|
->from(Customer::class, 'c')
|
||||||
;
|
;
|
||||||
|
|
||||||
$orderBy = 'c.' . $query->getOrderBy();
|
$qb->orderBy('c.' . $query->getOrderBy(), $query->getOrder());
|
||||||
$qb->orderBy($orderBy, $query->getOrder());
|
|
||||||
|
|
||||||
if ($query->isShowVisible()) {
|
if ($query->isShowVisible()) {
|
||||||
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
|
$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;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ class InvoiceRepository extends EntityRepository
|
|||||||
|
|
||||||
$qb
|
$qb
|
||||||
->select('i')
|
->select('i')
|
||||||
->distinct()
|
|
||||||
->from(Invoice::class, 'i')
|
->from(Invoice::class, 'i')
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -152,6 +151,13 @@ class InvoiceRepository extends EntityRepository
|
|||||||
|
|
||||||
$this->addPermissionCriteria($qb, $query->getCurrentUser());
|
$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;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,7 +255,6 @@ class ProjectRepository extends EntityRepository
|
|||||||
|
|
||||||
$qb
|
$qb
|
||||||
->select('p')
|
->select('p')
|
||||||
->distinct()
|
|
||||||
->from(Project::class, 'p')
|
->from(Project::class, 'p')
|
||||||
->leftJoin('p.customer', 'c')
|
->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;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user