Skip to content

Commit 7c6f96f

Browse files
Do not add JOINs for Filters without a value (#3703)
1 parent 0037f60 commit 7c6f96f

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Mercure: Do not use data in options when deleting (#4056)
99
* Doctrine: Support for foreign identifiers (#4042)
1010
* Doctrine: Support for binary UUID in search filter (#3774)
11+
* Doctrine: Do not add join or lookup for search filter with empty value (#3703)
1112
* JSON Schema: Allow generating documentation when property and method start from "is" (property `isActive` and method `isActive`) (#4064)
1213
* OpenAPI: Fix missing 422 responses in the documentation (#4086)
1314
* OpenAPI: Fix error when schema is empty (#4051)

src/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ protected function filterProperty(string $property, $value, Builder $aggregation
7777

7878
$matchField = $field = $property;
7979

80+
$values = $this->normalizeValues((array) $value, $property);
81+
if (null === $values) {
82+
return;
83+
}
84+
8085
$associations = [];
8186
if ($this->isPropertyNested($property, $resourceClass)) {
8287
[$matchField, $field, $associations] = $this->addLookupsForNestedProperty($property, $aggregationBuilder, $resourceClass);
@@ -87,11 +92,6 @@ protected function filterProperty(string $property, $value, Builder $aggregation
8792
*/
8893
$metadata = $this->getNestedMetadata($resourceClass, $associations);
8994

90-
$values = $this->normalizeValues((array) $value, $property);
91-
if (null === $values) {
92-
return;
93-
}
94-
9595
$caseSensitive = true;
9696

9797
if ($metadata->hasField($field) && !$metadata->hasAssociation($field)) {

src/Bridge/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
8181
$alias = $queryBuilder->getRootAliases()[0];
8282
$field = $property;
8383

84-
$associations = [];
85-
if ($this->isPropertyNested($property, $resourceClass)) {
86-
[$alias, $field, $associations] = $this->addJoinsForNestedProperty($property, $alias, $queryBuilder, $queryNameGenerator, $resourceClass);
87-
}
88-
8984
$values = $this->normalizeValues((array) $value, $property);
9085
if (null === $values) {
9186
return;
9287
}
9388

89+
$associations = [];
90+
if ($this->isPropertyNested($property, $resourceClass)) {
91+
[$alias, $field, $associations] = $this->addJoinsForNestedProperty($property, $alias, $queryBuilder, $queryNameGenerator, $resourceClass);
92+
}
93+
9494
$metadata = $this->getNestedMetadata($resourceClass, $associations);
9595

9696
if ($metadata->hasField($field)) {

tests/Bridge/Doctrine/Common/Filter/SearchFilterTestTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ private function provideApplyTestArguments(): array
466466
'relatedDummy.symfony' => 'exact',
467467
],
468468
],
469+
'empty nested property' => [
470+
[
471+
'relatedDummy.symfony' => null,
472+
],
473+
[
474+
'relatedDummy.symfony' => [],
475+
],
476+
],
469477
];
470478
}
471479
}

tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,10 @@ public function provideApplyTestData(): array
686686
],
687687
$filterFactory,
688688
],
689+
'empty nested property' => [
690+
[],
691+
$filterFactory,
692+
],
689693
]
690694
);
691695
}

tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ public function provideApplyTestData(): array
559559
],
560560
$filterFactory,
561561
],
562+
'empty nested property' => [
563+
sprintf('SELECT %s FROM %s %1$s', $this->alias, Dummy::class),
564+
[],
565+
$filterFactory,
566+
],
562567
]
563568
);
564569
}

0 commit comments

Comments
 (0)