I have a preUpdate
listener for an Entity where I do some calculations, set values etc.
In that listener I would like to remove some other related entities, but this does not seem to be flushed by the entity manager. How can I go about achieving this?
According to the Doctrine2 docs:
Changes to associations of the updated entity are never allowed in this event, since Doctrine cannot guarantee to correctly handle referential integrity at this point of the flush operation.
Which means you shouldn't mess with the entities during the preUpdate
event handling. I suggest you move your logic up to the service layer by using an entity manager. Write a specific method for updating your entitty and do all the complex stuff there. A nice example of an entity manager would be the FOSUserBundle's UserManager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With