mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Refresh and reload entities through session #6755
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 @Cartman34 on GitHub (Jun 11, 2021).
Hello,
I am getting some trouble to maintain some code source with Doctrine entities through session.
While registering an user, he may register his enterprise with an establishment with an address, Also he may be having a personal address and in most cases, this address is the same than the establishment.
An address is unique in database, so we are re-using an existing entity if we find it in database.
All these entities may be persisted in session while using the wizard. Some of them can or can not be persisted in database, I can not predict it for all of them.
I keep db persisted entities in session to keep relations but in fact, it should be reloaded before each usage. To do that, I am using my own way with a simple find($id) and get the db object.
From manual, I thought EntityManager::refresh() may do the job but in fact no, it returns an error: "Undefined index: 000000004156b3a300000000288c6c93" while flushing (it seems the entity should be currently persisted)
When getting a flush error, all my session's entities are corrupted because they got an ID in PHP object but they are not persisted in database (Whaaat ?).
All this system is complex and I am not sure I am using Symfony & Doctrine in the right way.
What are the best practices in case of entities in session ? What should I do ?