fix(doctrine): filter parent link from uri variables in fetch_data=false reference#8295
Open
soyuka wants to merge 1 commit into
Open
fix(doctrine): filter parent link from uri variables in fetch_data=false reference#8295soyuka wants to merge 1 commit into
soyuka wants to merge 1 commit into
Conversation
…lse reference getReference threw UnrecognizedIdentifierFields on subresource IRIs because the parent link (e.g. companyId) was passed as an entity identifier. Only short-circuit to getReference when all own identifiers are present; otherwise fall through to a query that resolves the link. Fixes api-platform#8124
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IriConverter::getResourceFromIri($iri, ['fetch_data' => false])on a subresource IRI (e.g./companies/{companyId}/employees/{id}) threwDoctrine\ORM\Exception\UnrecognizedIdentifierFieldsbecause the ORMItemProviderpassed the entire$uriVariablesarray — including the parent linkcompanyId— toEntityManager::getReference(). Doctrine rejects any key that is not an own identifier of the entity.The provider now reads the entity's own identifier field names, intersects them with
$uriVariables, and only short-circuits togetReference()when every own identifier is present (passing just those keys); otherwise it falls through to the normal query that resolves the link. This mirrors the existing ODMItemProviderbehaviour and correctly handles composite identifiers. Also removes the stale// todothat flagged this exact fragility.Reproduction
Following the docs Company/Employee subresource example, resolving an
EmployeeIRI withfetch_data: falseraisedUnrecognizedIdentifierFields ('companyId')instead of returning a reference. Also affectedSearchFilterwhen an IRI is passed.Test plan
testGetItemWithFetchDataFalseOnSubresourceFiltersParentLink).getReferencecalled with['id' => 2], not the parent link).IriConverterTest, and functional subresource suites pass locally.Fixes #8124