Fix merging of documents when not cascading references #2108
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.
Summary
The described issue only appears when not cascading merge operations. The problem is that the call to
registerManaged
after creating a new proxy object will return early since a document with that ID is already registered (the original proxy loaded in$managedCopy
. This leads to the new value for the association being different from the document that is being managed by the entity manager, which again causes issues on subsequent proxy initialisations.On a related note, I'm not sure why the merge logic includes creating a new proxy object for the managed copy and discarding the changes from the original. However, this is logic that was introduced 8 years ago to ORM, was ported to MongoDB ODM and wasn't changed in ORM since, so I don't feel comfortable changing this particular thing about it.