doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

Cloning or populating lazy-loaded entity with nullified id has unexpected behavior #11417

Open AntoineRoue opened 2 months ago

AntoineRoue commented 2 months ago

Bug Report

Q A
BC Break no
Version 3.1.2

Summary

Cloning a lazy-loaded entity or populating it after setting its id to null does not work properly.

Current behavior

When we do $entity->getEntityB(), B entity is lazy loaded. Then, if we set B entity's id to null before to populate it, and then we populate it, it populates the first B entity of the database, the one inserted first in the database.

If we clone a lazy loaded entity, persist and flush it, properties are nullified.

How to reproduce

I created a minimal repository whith these bugs here : https://github.com/AntoineRoue/doctrine-test

Expected behavior

In my opinion, a lazy-loaded entity should be populated just before its id is set to null or it's cloned.