Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing entities in preUpdate event lister

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?

like image 354
DavidW Avatar asked Dec 28 '22 07:12

DavidW


1 Answers

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

like image 156
kgilden Avatar answered Jan 04 '23 17:01

kgilden