Skip to content

fix(doctrine): resolve parent link toProperty during PUT create#8233

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/put-create-link-toproperty-7819
Jun 3, 2026
Merged

fix(doctrine): resolve parent link toProperty during PUT create#8233
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/put-create-link-toproperty-7819

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 3, 2026

Summary

In PersistProcessor, the PUT create-via-allowCreate arm (no previous_data) iterated uri-variable Links and wrote the raw scalar identifier onto the current entity, ignoring Link::toProperty and Link::fromClass. The default path overwrote the entity's own id; using identifiers: ['user'] as a workaround wrote a scalar UUID into the relation property, leaving the FK null on flush. Only the PUT-with-previous_data arm handled parent links correctly. This PR resolves a managed reference via ManagerRegistry::getManagerForClass()->getReference() and assigns it to the toProperty target instead of writing the scalar id. Composite identifier links pass an associative array to getReference. The legacy scalar write is preserved as a fallback when no parent manager is available or the target property is missing.

Reproduction

PUT on a sub-resource whose parent Link declares toProperty (e.g. userId => new Link(toProperty: 'user', fromClass: User::class)) with allowCreate: true overwrote the device's id with the parent URI variable instead of resolving the parent reference.

Test plan

  • Added failing unit test (PersistProcessorTest::testPersistPutCreateResolvesParentLinkViaToProperty) covering the bug.
  • Test passes after the fix.
  • Related test classes still pass locally (StandardPutTest, CustomPutTest, OperationResourceTest).

Fixes #7819

The PUT create-via-allowCreate branch of PersistProcessor ignored
Link::toProperty and Link::fromClass and wrote the raw scalar URI
identifier onto the current entity, overwriting its own id and leaving
the parent relation null. Only the PUT-with-previous-data branch handled
this correctly.

When a uri variable Link declares a toProperty + fromClass, resolve a
managed reference via ManagerRegistry::getManagerForClass and assign it
to the target property instead of writing the scalar id. Composite
identifier links pass an associative array to getReference. Falls back
to the legacy scalar write when no parent manager is found or the
property is missing, so existing self-link paths remain unchanged.

Fixes api-platform#7819
@soyuka soyuka merged commit 90bcfb0 into api-platform:4.3 Jun 3, 2026
106 of 108 checks passed
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