Versioned entity with composite id with foreign key can't be updated separately #5737

Closed
opened 2026-01-22 15:16:01 +01:00 by admin · 3 comments
Owner

Originally created by @etki on GitHub (Oct 12, 2017).

Originally assigned to: @ostrolucky on GitHub.

Hi! I'm hitting a rare issue with many-to-one mapping.
Imagine following relationship:

Root:
  id: uuid, id
  children: one-to-many<Child>
Child:
  root: many-to-one<Root>, id, join column = root_id
  index: integer, id
  version: integer

I can persist root with children, but this is what happens when i persist child separately:

  • UnitOfWork.createEntity is called, which extracts id through IdentifierFlattener as [root: <uuid>, index: <integer>]
  • Application kicks in and does it's work
  • UnitOfWork.commit() is called
  • BasicEntityPersister.update(entity) is called
  • .updateTable is successfully called, all ok here
  • It tries to assign default version value to entity (why? it's update, not create) and fetches id as $this->em->getUnitOfWork()->getEntityIdentifier($entity), which is already flattened and contains root key instead of root_id (BasicEntityPersister:369)
  • it all boils down to BasicEntityPersister.fetchVersionValue, which calls IdentifierFlattener.flattenIdentifier again
  • .flattenIdentifier is fed with already-flattened identifier, while it expects to find root_id in passed array so it throws an error

Doctrine version: v2.5.11 - this report may be already out-of-date

Originally created by @etki on GitHub (Oct 12, 2017). Originally assigned to: @ostrolucky on GitHub. Hi! I'm hitting a rare issue with many-to-one mapping. Imagine following relationship: ```yaml Root: id: uuid, id children: one-to-many<Child> Child: root: many-to-one<Root>, id, join column = root_id index: integer, id version: integer ``` I can persist root with children, but this is what happens when i persist child separately: - `UnitOfWork.createEntity` is called, which extracts id through `IdentifierFlattener` as `[root: <uuid>, index: <integer>]` - Application kicks in and does it's work - `UnitOfWork.commit()` is called - `BasicEntityPersister.update(entity)` is called - `.updateTable` is successfully called, all ok here - It tries to assign default version value to entity (why? it's update, not create) and **fetches id as `$this->em->getUnitOfWork()->getEntityIdentifier($entity)`, which is already flattened and contains root key instead of root_id** (BasicEntityPersister:369) - it all boils down to `BasicEntityPersister.fetchVersionValue`, which calls `IdentifierFlattener.flattenIdentifier` again - `.flattenIdentifier` is fed with already-flattened identifier, while it expects to find `root_id` in passed array so it throws an error Doctrine version: v2.5.11 - this report may be already out-of-date
admin closed this issue 2026-01-22 15:16:03 +01:00
Author
Owner

@lcobucci commented on GitHub (Oct 29, 2017):

@etki could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Oct 29, 2017): @etki could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing. You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@ostrolucky commented on GitHub (Aug 6, 2018):

Closing due to lack of feedback. If you can still reproduce in latest version, feel free to reopen.

@ostrolucky commented on GitHub (Aug 6, 2018): Closing due to lack of feedback. If you can still reproduce in latest version, feel free to reopen.
Author
Owner

@TsungHseinTsai commented on GitHub (Nov 5, 2020):

I hit the same issue.
An entity that has association primary key and versioned column will fail on updating if the variable nam of the association PK is different with column name. Just like Etki's entity example.

Doctrine version: v2.6.6

@TsungHseinTsai commented on GitHub (Nov 5, 2020): I hit the same issue. An entity that has association primary key and versioned column will fail on updating if the variable nam of the association PK is different with column name. Just like Etki's entity example. Doctrine version: v2.6.6
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5737