orm icon indicating copy to clipboard operation
orm copied to clipboard

Initializing a collection overwrites nulled field

Open insel-maz opened this issue 6 months ago • 0 comments

Bug Report

Q A
BC Break no?
Version 3.2.1 down to 2.x

Summary

When Doctrine fetches the entities for a PersistentCollection it overwrites the programmatically set null values in association fields for already managed (in the identity map) entities.

This happens by the if statement in https://github.com/doctrine/orm/blob/205b2f5f200c63f8cb22a26bfc0174071ed97d2c/src/Internal/Hydration/ObjectHydrator.php#L434.

Current behavior

The association field, which was just set to null by code, is overwritten with the persisted peer entity.

How to reproduce

In the following example there is a one-to-one association. One side gets set to null, but when a collection containing the entity is loaded, the field is restored with the peer entity.

https://github.com/insel-maz/doctrine-bug-collection-initialization-overwrites-field

Expected behavior

If an entity is already managed (in the identity map) Doctrine should not change the fields when fetching the database records for a PersistentCollection.

insel-maz avatar Aug 13 '24 18:08 insel-maz