diff --git a/src/Filter/ModelFilter.php b/src/Filter/ModelFilter.php index 4bb45040d..010c52355 100644 --- a/src/Filter/ModelFilter.php +++ b/src/Filter/ModelFilter.php @@ -94,7 +94,9 @@ protected function handleMultiple(ProxyQueryInterface $query, string $alias, Fil ); } - $this->applyWhere($query, $inExpression); + if ($inExpression->count() > 0) { + $this->applyWhere($query, $inExpression); + } } protected function association(ProxyQueryInterface $query, FilterData $data): array @@ -147,6 +149,10 @@ private function buildInExpression(ProxyQueryInterface $query, string $alias, Fi $orX = $queryBuilder->expr()->orX(); foreach ($data->getValue() as $value) { + if (!\is_object($value)) { + continue; + } + $andX = $queryBuilder->expr()->andX(); foreach ($metadata->getIdentifierValues($value) as $fieldName => $identifierValue) { diff --git a/tests/Filter/ModelFilterTest.php b/tests/Filter/ModelFilterTest.php index 16fc7ed5c..63353a07c 100644 --- a/tests/Filter/ModelFilterTest.php +++ b/tests/Filter/ModelFilterTest.php @@ -53,6 +53,25 @@ public function testFilterArray(): void static::assertTrue($filter->isActive()); } + public function testFilterNonObject(): void + { + $filter = new ModelFilter(); + $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); + + $proxyQuery = new ProxyQuery($this->createQueryBuilderStub()); + + $objects = [new \stdClass(), new \stdClass()]; + $filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray([ + 'type' => EqualOperatorType::TYPE_EQUAL, + 'value' => null, + ])); + + // the alias is now computer by the entityJoin method + self::assertSameQuery([], $proxyQuery); + self::assertSameQueryParameters([], $proxyQuery); + static::assertFalse($filter->isActive()); + } + public function testFilterArrayTypeIsNotEqual(): void { $filter = new ModelFilter();