Skip to content

Commit

Permalink
Revert "fix: search on nested sub-entity that doesn't use "id" as its…
Browse files Browse the repository at this point in the history
… ORM identifier (#5623)" (#5744)

This reverts commit b8cbdb1.
  • Loading branch information
soyuka authored Aug 11, 2023
1 parent ebf0310 commit ccad636
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 352 deletions.
9 changes: 0 additions & 9 deletions features/doctrine/search_filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1025,15 +1025,6 @@ Feature: Search filter on collections
And the response should be in JSON
And the JSON node "hydra:totalItems" should be equal to 1

@!mongodb
@createSchema
Scenario: Search on nested sub-entity that doesn't use "id" as its ORM identifier
Given there is a dummy entity with a sub entity with id "stringId" and name "someName"
When I send a "GET" request to "/dummy_with_subresource?subEntity=/dummy_subresource/stringId"
Then the response status code should be 200
And the response should be in JSON
And the JSON node "hydra:totalItems" should be equal to 1

@!mongodb
@createSchema
Scenario: Custom search filters can use Doctrine Expressions as join conditions
Expand Down
8 changes: 1 addition & 7 deletions src/Doctrine/Common/Filter/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@ protected function getIdFromValue(string $value): mixed
$iriConverter = $this->getIriConverter();
$item = $iriConverter->getResourceFromIri($value, ['fetch_data' => false]);

if (null === $this->identifiersExtractor) {
return $this->getPropertyAccessor()->getValue($item, 'id');
}

$identifiers = $this->identifiersExtractor->getIdentifiersFromItem($item);

return 1 === \count($identifiers) ? array_pop($identifiers) : $identifiers;
return $this->getPropertyAccessor()->getValue($item, 'id');
} catch (InvalidArgumentException) {
// Do nothing, return the raw value
}
Expand Down
5 changes: 1 addition & 4 deletions src/Doctrine/Orm/Filter/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
if ($metadata->hasField($field)) {
if ('id' === $field) {
$values = array_map($this->getIdFromValue(...), $values);
// todo: handle composite IDs
}

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

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

$associationResourceClass = $metadata->getAssociationTargetClass($field);
$associationMetadata = $this->getClassMetadata($associationResourceClass);
$associationFieldIdentifier = $associationMetadata->getIdentifierFieldNames()[0];
$associationFieldIdentifier = $metadata->getIdentifierFieldNames()[0];
$doctrineTypeField = $this->getDoctrineFieldType($associationFieldIdentifier, $associationResourceClass);

if (!$this->hasValidValues($values, $doctrineTypeField)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<service id="api_platform.doctrine_mongodb.odm.search_filter" class="ApiPlatform\Doctrine\Odm\Filter\SearchFilter" public="false" abstract="true">
<argument type="service" id="doctrine_mongodb" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="api_platform.identifiers_extractor" on-invalid="ignore" />
<argument type="service" id="api_platform.identifiers_extractor.cached" on-invalid="ignore" />
<argument type="service" id="api_platform.property_accessor" />
<argument type="service" id="logger" on-invalid="ignore" />
<argument key="$nameConverter" type="service" id="api_platform.name_converter" on-invalid="ignore"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/Resources/config/doctrine_orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="api_platform.property_accessor" />
<argument type="service" id="logger" on-invalid="ignore" />
<argument key="$identifiersExtractor" type="service" id="api_platform.identifiers_extractor" on-invalid="ignore" />
<argument key="$identifiersExtractor" type="service" id="api_platform.identifiers_extractor.cached" on-invalid="ignore" />
<argument key="$nameConverter" type="service" id="api_platform.name_converter" on-invalid="ignore" />
</service>
<service id="ApiPlatform\Doctrine\Orm\Filter\SearchFilter" alias="api_platform.doctrine.orm.search_filter" />
Expand Down
16 changes: 0 additions & 16 deletions tests/Behat/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyPassenger;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyProduct;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyProperty;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummySubEntity;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTravel;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyWithSubEntity;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EntityClassWithDateTime;
Expand Down Expand Up @@ -2145,20 +2143,6 @@ public function thereIsAResourceUsingEntityClassAndDateTime(): void
$this->manager->flush();
}

/**
* @Given there is a dummy entity with a sub entity with id :strId and name :name
*/
public function thereIsADummyWithSubEntity(string $strId, string $name): void
{
$subEntity = new DummySubEntity($strId, $name);
$mainEntity = new DummyWithSubEntity();
$mainEntity->setSubEntity($subEntity);
$mainEntity->setName('main');
$this->manager->persist($subEntity);
$this->manager->persist($mainEntity);
$this->manager->flush();
}

private function isOrm(): bool
{
return null !== $this->schemaTool;
Expand Down
41 changes: 0 additions & 41 deletions tests/Fixtures/TestBundle/ApiResource/Issue5605/MainResource.php

This file was deleted.

39 changes: 0 additions & 39 deletions tests/Fixtures/TestBundle/ApiResource/Issue5605/SubResource.php

This file was deleted.

61 changes: 0 additions & 61 deletions tests/Fixtures/TestBundle/Entity/DummySubEntity.php

This file was deleted.

60 changes: 0 additions & 60 deletions tests/Fixtures/TestBundle/Entity/DummyWithSubEntity.php

This file was deleted.

59 changes: 0 additions & 59 deletions tests/Fixtures/TestBundle/State/Issue5605/MainResourceProvider.php

This file was deleted.

Loading

0 comments on commit ccad636

Please sign in to comment.