mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Overwriting entities relation field when hydrating a collection #6913
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 @mlebkowski on GitHub (Jan 25, 2022).
Bug Report
Doctrine needlessly overwrites entities relation field in certain circumstances.
The scenario is described in details here: https://github.com/mlebkowski/doctrine-bug
I have no idea what’s happening, but I was able to reproduce the bug in as narrow of a scenario as I could.
Summary
See the related code in: https://github.com/mlebkowski/doctrine-bug
Prerequisites
AuthorandBookin this example)Book::$ownertoUser)src/User.php:21)Account::$usertoUser). As far as I understand the bug, this is only required, so we get a proxy of the entity instead of the entity itself.Test scenario
Bookentity using a non-pk field (Book::$isbn)Account(container) class to get theUserentity as a proxyUser::$ownerfieldAuthor::$bookscollection, and hydrate it (toArray())Current behavior
The
Book::$ownerfield isnullHow to reproduce
https://github.com/mlebkowski/doctrine-bug
Expected behavior
The
Book::$owneris not null and holds the previously assignedUserproxy entity