Skip to content

[Turbo] Fix broadcasting an entity whose identifier is made of associations - #3847

Merged
Kocal merged 1 commit into
symfony:3.xfrom
Kocal:fix/turbo-composite-association-id
Sep 8, 2026
Merged

Kocal merged 1 commit into
symfony:3.xfrom
Kocal:fix/turbo-composite-association-id

Conversation

@Kocal

@Kocal Kocal commented Sep 8, 2026

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
Deprecations? no
Documentation? no
Issues Fix #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 #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.

…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.
@Kocal Kocal self-assigned this Sep 8, 2026
@carsonbot carsonbot added Bug Bug Fix Turbo Status: Needs Review Needs to be reviewed labels Sep 8, 2026
@Kocal
Kocal merged commit 33bbea6 into symfony:3.x Sep 8, 2026
34 checks passed
@Kocal
Kocal deleted the fix/turbo-composite-association-id branch September 8, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Bug Fix Status: Needs Review Needs to be reviewed Turbo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Turbo] Doesn't work with entity that uses composite primary key

2 participants