Fixed visits count multiplied by the number of tags when ordering and filtering by text

This commit is contained in:
Alejandro Celaya 2018-08-01 20:31:54 +02:00
parent f4b569c245
commit a79c1f580e

View File

@ -51,7 +51,7 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
$order = \is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
if (\in_array($fieldName, ['visits', 'visitsCount', 'visitCount'], true)) {
$qb->addSelect('COUNT(v) AS totalVisits')
$qb->addSelect('COUNT(DISTINCT v) AS totalVisits')
->leftJoin('s.visits', 'v')
->groupBy('s')
->orderBy('totalVisits', $order);