Skip to content

Commit fc55edd

Browse files
authored
Search filter should not use DbRef for association (#2575)
1 parent 3357779 commit fc55edd

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

features/doctrine/search_filter.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ Feature: Search filter on collections
415415
And the JSON node "_embedded.item[1]._links.relatedDummies" should have 3 elements
416416
And the JSON node "_embedded.item[2]._links.relatedDummies" should have 3 elements
417417

418+
@createSchema
419+
Scenario: Search by related collection id
420+
Given there are 2 dummy objects having each 2 relatedDummies
421+
When I add "Accept" header equal to "application/hal+json"
422+
And I send a "GET" request to "/dummies?relatedDummies=3"
423+
Then the response status code should be 200
424+
And the response should be in JSON
425+
And the JSON node "totalItems" should be equal to "1"
426+
And the JSON node "_links.item" should have 1 element
427+
And the JSON node "_links.item[0].href" should be equal to "/dummies/2"
428+
418429
@createSchema
419430
Scenario: Get collection by id equals 9.99 which is not possible
420431
Given there are 30 dummy objects

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function filterProperty(string $property, $value, Builder $aggregation
135135

136136
$aggregationBuilder
137137
->match()
138-
->field("$matchField.\$id")
138+
->field($matchField)
139139
->in($values);
140140
}
141141

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ public function provideApplyTestData(): array
346346
],
347347
[
348348
'$match' => [
349-
'relatedDummy.$id' => [
349+
'relatedDummy' => [
350350
'$in' => [
351-
'foo',
351+
0,
352352
],
353353
],
354354
],
@@ -472,9 +472,9 @@ public function provideApplyTestData(): array
472472
[
473473
[
474474
'$match' => [
475-
'relatedDummy.$id' => [
475+
'relatedDummy' => [
476476
'$in' => [
477-
'exact',
477+
0,
478478
],
479479
],
480480
],
@@ -511,7 +511,7 @@ public function provideApplyTestData(): array
511511
[
512512
[
513513
'$match' => [
514-
'relatedDummy.$id' => [
514+
'relatedDummy' => [
515515
'$in' => [
516516
1,
517517
'2',
@@ -521,7 +521,7 @@ public function provideApplyTestData(): array
521521
],
522522
[
523523
'$match' => [
524-
'relatedDummies.$id' => [
524+
'relatedDummies' => [
525525
'$in' => [
526526
'1',
527527
],

tests/Fixtures/TestBundle/Document/RelatedToDummyFriend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RelatedToDummyFriend
5151
private $description;
5252

5353
/**
54-
* @ODM\ReferenceOne(targetDocument=DummyFriend::class)
54+
* @ODM\ReferenceOne(targetDocument=DummyFriend::class, storeAs="id")
5555
* @Groups({"fakemanytomany", "friends"})
5656
* @Assert\NotNull
5757
*/

0 commit comments

Comments
 (0)