From 81a34d73c2f4b7f022ee5de0d6ca567b98f72604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 21 Jan 2025 15:58:12 +0100 Subject: [PATCH] fix: correctly filter by multiple hotels --- src/Repository/AssignmentRepository.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index e3bb112..7992054 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -127,11 +127,15 @@ class AssignmentRepository extends ServiceEntityRepository ; } - foreach ($filterDto->getHotels() as $hotel) { - $qb - ->andWhere($qb->expr()->like('destination.hotel', ':hotel')) - ->setParameter('hotel', '%'.$hotel.'%') - ; + if (0 < count($filterDto->getHotels())) { + $constraints = []; + foreach ($filterDto->getHotels() as $index => $hotel) { + $constraints[] = $qb->expr()->like('destination.hotel', ':hotel'.$index); + } + $qb->andWhere($qb->expr()->orX(...$constraints)); + foreach ($filterDto->getHotels() as $index => $hotel) { + $qb->setParameter('hotel'.$index, '%'.$hotel.'%'); + } } if (null !== $duration = $filterDto->getDuration()) {