Skip to content

Commit ccad636

Browse files
authored
Revert "fix: search on nested sub-entity that doesn't use "id" as its ORM identifier (#5623)" (#5744)
This reverts commit b8cbdb1.
1 parent ebf0310 commit ccad636

File tree

13 files changed

+4
-352
lines changed

13 files changed

+4
-352
lines changed

features/doctrine/search_filter.feature

-9
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,6 @@ Feature: Search filter on collections
10251025
And the response should be in JSON
10261026
And the JSON node "hydra:totalItems" should be equal to 1
10271027

1028-
@!mongodb
1029-
@createSchema
1030-
Scenario: Search on nested sub-entity that doesn't use "id" as its ORM identifier
1031-
Given there is a dummy entity with a sub entity with id "stringId" and name "someName"
1032-
When I send a "GET" request to "/dummy_with_subresource?subEntity=/dummy_subresource/stringId"
1033-
Then the response status code should be 200
1034-
And the response should be in JSON
1035-
And the JSON node "hydra:totalItems" should be equal to 1
1036-
10371028
@!mongodb
10381029
@createSchema
10391030
Scenario: Custom search filters can use Doctrine Expressions as join conditions

src/Doctrine/Common/Filter/SearchFilterTrait.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,7 @@ protected function getIdFromValue(string $value): mixed
124124
$iriConverter = $this->getIriConverter();
125125
$item = $iriConverter->getResourceFromIri($value, ['fetch_data' => false]);
126126

127-
if (null === $this->identifiersExtractor) {
128-
return $this->getPropertyAccessor()->getValue($item, 'id');
129-
}
130-
131-
$identifiers = $this->identifiersExtractor->getIdentifiersFromItem($item);
132-
133-
return 1 === \count($identifiers) ? array_pop($identifiers) : $identifiers;
127+
return $this->getPropertyAccessor()->getValue($item, 'id');
134128
} catch (InvalidArgumentException) {
135129
// Do nothing, return the raw value
136130
}

src/Doctrine/Orm/Filter/SearchFilter.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
196196
if ($metadata->hasField($field)) {
197197
if ('id' === $field) {
198198
$values = array_map($this->getIdFromValue(...), $values);
199-
// todo: handle composite IDs
200199
}
201200

202201
if (!$this->hasValidValues($values, $this->getDoctrineFieldType($property, $resourceClass))) {
@@ -218,11 +217,9 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
218217
}
219218

220219
$values = array_map($this->getIdFromValue(...), $values);
221-
// todo: handle composite IDs
222220

223221
$associationResourceClass = $metadata->getAssociationTargetClass($field);
224-
$associationMetadata = $this->getClassMetadata($associationResourceClass);
225-
$associationFieldIdentifier = $associationMetadata->getIdentifierFieldNames()[0];
222+
$associationFieldIdentifier = $metadata->getIdentifierFieldNames()[0];
226223
$doctrineTypeField = $this->getDoctrineFieldType($associationFieldIdentifier, $associationResourceClass);
227224

228225
if (!$this->hasValidValues($values, $doctrineTypeField)) {

src/Symfony/Bundle/Resources/config/doctrine_mongodb_odm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<service id="api_platform.doctrine_mongodb.odm.search_filter" class="ApiPlatform\Doctrine\Odm\Filter\SearchFilter" public="false" abstract="true">
117117
<argument type="service" id="doctrine_mongodb" />
118118
<argument type="service" id="api_platform.iri_converter" />
119-
<argument type="service" id="api_platform.identifiers_extractor" on-invalid="ignore" />
119+
<argument type="service" id="api_platform.identifiers_extractor.cached" on-invalid="ignore" />
120120
<argument type="service" id="api_platform.property_accessor" />
121121
<argument type="service" id="logger" on-invalid="ignore" />
122122
<argument key="$nameConverter" type="service" id="api_platform.name_converter" on-invalid="ignore"/>

src/Symfony/Bundle/Resources/config/doctrine_orm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<argument type="service" id="api_platform.iri_converter" />
153153
<argument type="service" id="api_platform.property_accessor" />
154154
<argument type="service" id="logger" on-invalid="ignore" />
155-
<argument key="$identifiersExtractor" type="service" id="api_platform.identifiers_extractor" on-invalid="ignore" />
155+
<argument key="$identifiersExtractor" type="service" id="api_platform.identifiers_extractor.cached" on-invalid="ignore" />
156156
<argument key="$nameConverter" type="service" id="api_platform.name_converter" on-invalid="ignore" />
157157
</service>
158158
<service id="ApiPlatform\Doctrine\Orm\Filter\SearchFilter" alias="api_platform.doctrine.orm.search_filter" />

tests/Behat/DoctrineContext.php

-16
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@
128128
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyPassenger;
129129
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyProduct;
130130
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyProperty;
131-
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummySubEntity;
132131
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
133132
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTravel;
134-
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyWithSubEntity;
135133
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
136134
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
137135
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EntityClassWithDateTime;
@@ -2145,20 +2143,6 @@ public function thereIsAResourceUsingEntityClassAndDateTime(): void
21452143
$this->manager->flush();
21462144
}
21472145

2148-
/**
2149-
* @Given there is a dummy entity with a sub entity with id :strId and name :name
2150-
*/
2151-
public function thereIsADummyWithSubEntity(string $strId, string $name): void
2152-
{
2153-
$subEntity = new DummySubEntity($strId, $name);
2154-
$mainEntity = new DummyWithSubEntity();
2155-
$mainEntity->setSubEntity($subEntity);
2156-
$mainEntity->setName('main');
2157-
$this->manager->persist($subEntity);
2158-
$this->manager->persist($mainEntity);
2159-
$this->manager->flush();
2160-
}
2161-
21622146
private function isOrm(): bool
21632147
{
21642148
return null !== $this->schemaTool;

tests/Fixtures/TestBundle/ApiResource/Issue5605/MainResource.php

-41
This file was deleted.

tests/Fixtures/TestBundle/ApiResource/Issue5605/SubResource.php

-39
This file was deleted.

tests/Fixtures/TestBundle/Entity/DummySubEntity.php

-61
This file was deleted.

tests/Fixtures/TestBundle/Entity/DummyWithSubEntity.php

-60
This file was deleted.

tests/Fixtures/TestBundle/State/Issue5605/MainResourceProvider.php

-59
This file was deleted.

0 commit comments

Comments
 (0)