Replies: 1 comment 2 replies
-
Likely the relationship isn't saved because of the reason you suspect - storing in $_SESSION isn't recursive. I can't think of a reason why you would need to create an object on one page, but save it on another. You might want to take a look at your design and see if it can be improved. If not, how about not storing the object itself in $_SESSION, but just its properties. Then you can re-create it–and any related objects– on the page where the object gets saved. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
putting a Model in session works as expected even if the model has never been saved.
The id of the model will still be null when the object is retrieved from the session and the object save succeeds as normal across requests.
If a another Model object is created and set on the first one via a relationship (thru a setter or a magic property) and the two are not saved before storing the first object in session, the relationship is lost when the object is retrieved.
I have not investigated why this happens (if it's because storing object in session does not support recursion or because the relationship setter does not store the second object within the other) but this leads to ugly code when data is populated and prepared in a request for the subsequent save in a following request.
What is causing this behavior? Is there a practical workaround to store the full chain of unsaved object using just the one which would be finally saved?
Hope I expressed clearly the problem, seemed easier to explain before i started writing this :)
Beta Was this translation helpful? Give feedback.
All reactions