Refresh and reload entities through session #8766
Unanswered
Cartman34
asked this question in
Support Questions
Replies: 1 comment 3 replies
-
In my opinion you should not store the entity in the session, but convert it into either just the ID or all the other relevant information using a data transfer object. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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 ?
Beta Was this translation helpful? Give feedback.
All reactions