mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-872: $em->persist() during an event callback doesn't work, causes subsequent flush() calls to fail #1080
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Nov 10, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user felicitus:
Version from GIT
When doing a $em->persist() operation during an event callback, Doctrine2 simply does nothing with the entity. If this should work, it should be fixed. If this shouldn't work, Doctrine should throw an exception.
Example code:
As you can see from my comments, Doctrine2 becomes confused if you persist() something inside an event handler. Even a fresh EntityB will not be persisted from the main code unless you remove persist() from EntityA's event handler.
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by @beberlei:
Please see the docs on Events. Calling persist (or any EM method) from lifecycle events is not allowed.
http://www.doctrine-project.org/projects/orm/2.0/docs/reference/events/en#implementing-event-listeners:postupdate,-postremove,-postpersist
If you want to add additional changes during flush you can (mostly) only achieve this using the "onFlush" event:
http://www.doctrine-project.org/projects/orm/2.0/docs/reference/events/en#implementing-event-listeners:onflush
@doctrinebot commented on GitHub (Nov 10, 2010):
Issue was closed with resolution "Invalid"