mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
PrePersist event doesn't fire on subsequent persist #5625
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 @josefsabl on GitHub (Aug 1, 2017).
Originally assigned to: @alcaeus on GitHub.
I am not sure if this is a bug or a limitation or mistunderstood feature. It just works in a different way than I expected.
Let's assume I want to validate field of a document and set isInvalid field to TRUE if certain criteria is not met.
I would assert that this test would not fail. But the second persist obviously doesn't fire PrePersist event.
I am sure that by looking into code I would find out that it is designed like that intentionally. But isn't it incorrect behavior? I would understand that the second persist will not fire PrePersist as the second persist can be considered an update, but PreUpdate isn't fired either.
Would someone please clarify this or correct my assumptions and propose a solution?
Thank you.
@alcaeus commented on GitHub (Aug 1, 2017):
The second call to
persistis a no-op since the entity is already managed by the entity manager. It only has relevance if you're using an explicit change tracking policy, in which case it marks the entity for changeset computation.Changes like these should be done in an
onFlushhandler since they require changeset recomputation.@josefsabl commented on GitHub (Aug 2, 2017):
I resolved this by skipping doctrine events altogether and implemented custom DocumentManager that looks a bit like this:
@alcaeus commented on GitHub (Aug 2, 2017):
Oh, one more thing: this is The ORM repository, not ODM. Please open issues against doctrine/mongodb-odm in the future.