mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Initializing a collection overwrites nulled field #7408
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 @insel-maz on GitHub (Aug 13, 2024).
Bug Report
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
205b2f5f20/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.