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.
Bug Report
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.