Symfony 2 - flush in postUpdate fire preUpdate event
doctrine-orm, event-listener, symfony
Solution
Actually, this is a problem from doctrine Doctrine Issue DDC-2726. Solved it by adding a clear call on the entity manager after the flush in the listener so the 3-rd argument to that constructor, which is actually the entityChangeSets, will be re-written.
Problem
I detected this problem "thanks" to an exception I got: ``` Catchable Fatal Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be an array, null given, called in /.../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php on line 804 and defined in /.../vendor/doctrine/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php line 28 ``` I am working on a project that requieres a specific logic: When the `order` field in entity `book` is modified, I need to update field `books_order_modified_at` in the parent entity `bookstore` (this field allows me to know whether the order of books in a bookstore was changed). I decided to do it in an event listener since there are many places in the code that might change the order of books. I didn't find any way to update a related entity from `preUpdate` event, so I have a private field in the listener class which I use to tell the `postUpdate` event to update the relevant `bookstore` entity. My problem is that when I do so the `preUpdate` event of the `book` entity is fired. When I check the change-set it contains only the `modified_at` field, but it has the same value before and after. If someone has another idea how to solve the problem - great. If not - any idea how can I prevent the `preUpdate` event from being fired when the flush is called in teh `postUpdate` event??