Skip to content

fix(doctrine): filter parent link from uri variables in fetch_data=false reference#8295

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/iri-fetch-data-false-subresource-8124
Open

fix(doctrine): filter parent link from uri variables in fetch_data=false reference#8295
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/iri-fetch-data-false-subresource-8124

Conversation

@soyuka

@soyuka soyuka commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

IriConverter::getResourceFromIri($iri, ['fetch_data' => false]) on a subresource IRI (e.g. /companies/{companyId}/employees/{id}) threw Doctrine\ORM\Exception\UnrecognizedIdentifierFields because the ORM ItemProvider passed the entire $uriVariables array — including the parent link companyId — to EntityManager::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 to getReference() 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 ODM ItemProvider behaviour and correctly handles composite identifiers. Also removes the stale // todo that flagged this exact fragility.

Reproduction

Following the docs Company/Employee subresource example, resolving an Employee IRI with fetch_data: false raised UnrecognizedIdentifierFields ('companyId') instead of returning a reference. Also affected SearchFilter when an IRI is passed.

Test plan

  • Added failing test covering the bug (testGetItemWithFetchDataFalseOnSubresourceFiltersParentLink).
  • Test passes after the fix (getReference called with ['id' => 2], not the parent link).
  • ORM State suite, IriConverterTest, and functional subresource suites pass locally.

Fixes #8124

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant