[PR #1173] Fix merging of entities with associations to identical entities. #9235

Closed
opened 2026-01-22 16:03:40 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/1173

State: closed
Merged: No


Without this patch, when an entity that refers multiple times to the same
associated entity gets merged, the second references becomes null.

The main issue is that even though doMerge returns a managed copy, that value
is not used while cascading the merge. These identicial entities are already
detected through the visitor map, but they are ignored. There should be some
refactoring so cascadeMerge calls a function that checks if the parent must be
updated, based on the return value of its call to doMerge. However, this patch
tries to impact the code as little as possible, and only introduces a new
function to avoid duplicate code.

The secondary issue arises when using inverted associations. In that case, it
is possible that an entity to be merged is already merged, so the the visitor
map is looked up by the hash of a managed copy instead of the original entity.
This means that in this case the visitor map entries should also be set to the
entity, instead of being set to 'true'.

**Original Pull Request:** https://github.com/doctrine/orm/pull/1173 **State:** closed **Merged:** No --- Without this patch, when an entity that refers multiple times to the same associated entity gets merged, the second references becomes null. The main issue is that even though doMerge returns a managed copy, that value is not used while cascading the merge. These identicial entities are already detected through the visitor map, but they are ignored. There should be some refactoring so cascadeMerge calls a function that checks if the parent must be updated, based on the return value of its call to doMerge. However, this patch tries to impact the code as little as possible, and only introduces a new function to avoid duplicate code. The secondary issue arises when using inverted associations. In that case, it is possible that an entity to be merged is already merged, so the the visitor map is looked up by the hash of a managed copy instead of the original entity. This means that in this case the visitor map entries should also be set to the entity, instead of being set to 'true'.
admin added the pull-request label 2026-01-22 16:03:40 +01:00
admin closed this issue 2026-01-22 16:03:40 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9235