mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Merge is not working as expected #6108
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sks40gb on GitHub (Nov 20, 2018).
Bug Report
Summary
Merge is not working for parent and children relation. There is an parent object and its children mapped through @OneToMany. Whenever
mergeis called parent is being updated however new children are added instead of updating the record.Current behavior
On
mergeparent (current) object is updated but new children are added for unmanaged object.How to reproduce
I am getting the following json data from the client. JSON contains the parent and child details as below -
I am mapping these json data to Parent and Child Object.
Parent
Child
Expected behavior
It should update Parent and Children if
idis already available and add new record ifidis not available.@lcobucci commented on GitHub (Nov 20, 2018):
@sks40gb merge was removed from v3 and is being deprecate (with no replacement) on v2.7. The reason is because it doesn't support all edge cases and has an inconsistent behaviour.
The recommendation is to manipulate the objects instead of delegating that to the ORM.
@sks40gb commented on GitHub (Nov 20, 2018):
@lcobucci - Thanks for your comment. This is really awkward, instead of fixing the inconsistent behaviour issue. The feature
mergeitself is being removed.Merge is really very handy when it comes to updating the large object which has multiple children.
Now everything has to be done manually like adding, removing and updating the child object.
I have java hibernate background which works like a charm and I thought since Doctrine is inspired by it. it would be covering not all but important feature like merge.
Anyway do you have any reference how can we have handle this kind of scenario
@Majkl578 commented on GitHub (Nov 20, 2018):
Merge/detach stuff was surrounded with multiple inconsistent behaviours and gotchas, hence it's been removed.
There could be a merger tool, standalone to ORM, that would merge two entities just like
EntityManager::merge()does.