[Turbo] Fix broadcasting an entity whose identifier is made of associations - #3847
Merged
Merged
Conversation
…ations | Q | A | -------------- | --- | Bug fix? | yes | New feature? | no | Deprecations? | no | Documentation? | no | Issues | Fix symfony#1856 | License | MIT Entities whose primary key is made up of associations (the usual join-entity shape) couldn't be broadcast at all, as reported in symfony#1856. `ClassMetadata::getIdentifierValues()` returns the related entities themselves instead of their identifiers, and every consumer then runs `implode('-', $id)` on them, which throws `Object of class App\Entity\ClassA could not be converted to string`. `IdAccessor::getIdentifierValues()` now reads the identifier and replaces any field mapped as an association with the identifier of the entity it points to. It checks the mapping of the field, not the class of the value, so it still works when the association is a lazy proxy, and an identifier held in a value object such as a UUID is left alone since it's a plain column. Both producers now go through this accessor: `IdAccessor::getEntityId()`, and `BroadcastListener`, which used to read the identifier values itself and never reached the accessor at all: that's the exact path in the reported stack trace. The listener still gets its `EntityManager` from the flush event it's already handed, so nothing new is injected into it. This is covered by tests on the create path and the update path; the latter reloads the entity first, which under Doctrine ORM 2 turns the identifier associations into real proxies.
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.
Entities whose primary key is made up of associations (the usual join-entity shape) couldn't be broadcast at all, as reported in #1856.
ClassMetadata::getIdentifierValues()returns the related entities themselves instead of their identifiers, and every consumer then runsimplode('-', $id)on them, which throwsObject of class App\Entity\ClassA could not be converted to string.IdAccessor::getIdentifierValues()now reads the identifier and replaces any field mapped as an association with the identifier of the entity it points to. It checks the mapping of the field, not the class of the value, so it still works when the association is a lazy proxy, and an identifier held in a value object such as a UUID is left alone since it's a plain column.Both producers now go through this accessor:
IdAccessor::getEntityId(), andBroadcastListener, which used to read the identifier values itself and never reached the accessor at all: that's the exact path in the reported stack trace. The listener still gets itsEntityManagerfrom the flush event it's already handed, so nothing new is injected into it. This is covered by tests on the create path and the update path; the latter reloads the entity first, which under Doctrine ORM 2 turns the identifier associations into real proxies.