I'm trying to disable an entity event from outside of an entity in Doctrine 2. Everytime we insert a new record into our table, few file operations need to be run, which have been implemented in a method with the prePersist annotation. However I also need to run some data fixtures and skip the file operation part as part of the testing.
Basically I'm asking if it's possible to disable all prePersist events through the entity manager without changing anything in the entity.
If you are ok with completely removing the life cycle callbacks then you can just blank out the callbacks manually. This is useful in the case of dynamic fixture generation. You simply do this:
$this->em->getClassMetadata(get_class($object))->setLifecycleCallbacks(array());
Thanks to Jeremy Mikola (@jmikola) for pointing me in the right direction.
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