fix(doctrine): resolve parent link toProperty during PUT create#8233
Merged
soyuka merged 1 commit intoJun 3, 2026
Merged
Conversation
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
1 task
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
In
PersistProcessor, the PUT create-via-allowCreatearm (noprevious_data) iterated uri-variableLinks and wrote the raw scalar identifier onto the current entity, ignoringLink::toPropertyandLink::fromClass. The default path overwrote the entity's own id; usingidentifiers: ['user']as a workaround wrote a scalar UUID into the relation property, leaving the FK null on flush. Only the PUT-with-previous_dataarm handled parent links correctly. This PR resolves a managed reference viaManagerRegistry::getManagerForClass()->getReference()and assigns it to thetoPropertytarget instead of writing the scalar id. Composite identifier links pass an associative array togetReference. 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
LinkdeclarestoProperty(e.g.userId => new Link(toProperty: 'user', fromClass: User::class)) withallowCreate: trueoverwrote the device's id with the parent URI variable instead of resolving the parent reference.Test plan
PersistProcessorTest::testPersistPutCreateResolvesParentLinkViaToProperty) covering the bug.StandardPutTest,CustomPutTest,OperationResourceTest).Fixes #7819