fix group by with ONLY_FULL_GROUP_BY mode (#1830)

This commit is contained in:
Kevin Papst
2020-07-18 10:16:15 +02:00
committed by GitHub
parent 7907b43ef7
commit 93a23f3fa3
4 changed files with 28 additions and 23 deletions

View File

@@ -275,29 +275,25 @@ class ActivityRepository extends EntityRepository
$where = $qb->expr()->andX();
if (\in_array($query->getVisibility(), [ActivityQuery::SHOW_VISIBLE, ActivityQuery::SHOW_HIDDEN])) {
if (!$query->isShowBoth()) {
if (!$query->isGlobalsOnly()) {
$where->add(
$qb->expr()->orX(
$qb->expr()->eq('c.visible', ':customer_visible'),
$qb->expr()->isNull('c.visible')
$qb->expr()->isNull('a.project'),
$qb->expr()->andX(
$qb->expr()->eq('c.visible', ':is_visible'),
$qb->expr()->eq('p.visible', ':is_visible')
)
)
);
$where->add(
$qb->expr()->orX(
$qb->expr()->eq('p.visible', ':project_visible'),
$qb->expr()->isNull('p.visible')
)
);
$qb->setParameter('project_visible', true, \PDO::PARAM_BOOL);
$qb->setParameter('customer_visible', true, \PDO::PARAM_BOOL);
$qb->setParameter('is_visible', true, \PDO::PARAM_BOOL);
}
$where->add('a.visible = :visible');
$where->add($qb->expr()->eq('a.visible', ':visible'));
if (ActivityQuery::SHOW_VISIBLE === $query->getVisibility()) {
if ($query->isShowVisible()) {
$qb->setParameter('visible', true, \PDO::PARAM_BOOL);
} elseif (ActivityQuery::SHOW_HIDDEN === $query->getVisibility()) {
} elseif ($query->isShowHidden()) {
$qb->setParameter('visible', false, \PDO::PARAM_BOOL);
}
}
@@ -359,8 +355,10 @@ 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 / pagination results
// $qb->addGroupBy('a.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('a.id')->addGroupBy($orderBy);
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -189,6 +189,7 @@ class CustomerRepository extends EntityRepository
->from(Customer::class, 'c')
->orderBy('c.name', 'ASC');
// TODO this where and the next if($query->hasCustomers()) should go into their own $qb->expr()->orX()
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
$qb->setParameter('visible', true, \PDO::PARAM_BOOL);
@@ -219,10 +220,10 @@ class CustomerRepository extends EntityRepository
$orderBy = 'c.' . $query->getOrderBy();
$qb->orderBy($orderBy, $query->getOrder());
if (CustomerQuery::SHOW_VISIBLE == $query->getVisibility()) {
if ($query->isShowVisible()) {
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
$qb->setParameter('visible', true, \PDO::PARAM_BOOL);
} elseif (CustomerQuery::SHOW_HIDDEN == $query->getVisibility()) {
} elseif ($query->isShowHidden()) {
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
$qb->setParameter('visible', false, \PDO::PARAM_BOOL);
}
@@ -269,8 +270,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 / pagination results
// $qb->addGroupBy('c.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('c.id')->addGroupBy($orderBy);
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -141,8 +141,10 @@ class InvoiceRepository extends EntityRepository
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// $qb->addGroupBy('i.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('i.id')->addGroupBy($orderBy);
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -271,15 +271,15 @@ class ProjectRepository extends EntityRepository
$qb->addOrderBy($orderBy, $query->getOrder());
if (\in_array($query->getVisibility(), [ProjectQuery::SHOW_VISIBLE, ProjectQuery::SHOW_HIDDEN])) {
if (!$query->isShowBoth()) {
$qb
->andWhere($qb->expr()->eq('p.visible', ':visible'))
->andWhere($qb->expr()->eq('c.visible', ':customer_visible'))
;
if (ProjectQuery::SHOW_VISIBLE === $query->getVisibility()) {
if ($query->isShowVisible()) {
$qb->setParameter('visible', true, \PDO::PARAM_BOOL);
} elseif (ProjectQuery::SHOW_HIDDEN === $query->getVisibility()) {
} elseif ($query->isShowHidden()) {
$qb->setParameter('visible', false, \PDO::PARAM_BOOL);
}
@@ -368,8 +368,10 @@ 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 / pagination results
// $qb->addGroupBy('p.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
$qb->addGroupBy('p.id')->addGroupBy($orderBy);
// $qb->addGroupBy($orderBy);
return $qb;
}