mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-113: Cascaded persist avoids LifecycleCallbacks #144
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 4, 2009).
Jira issue originally created by user nicokaiser:
When an Entity is created by 'cascade={"persist"}', its LifecycleCallbacks (e.g. "PrePersist"!) are not invoked.
When it is persisted explicitly, everything workes fine and the events are called...
@doctrinebot commented on GitHub (Dec 11, 2009):
Comment created by @beberlei:
Works for me on trunk, added test-case that proves it (Doctrine\Tests\ORM\Functional\LifecycleCallbackTest::testCascadedEntitiesCallsPrePersist())
@doctrinebot commented on GitHub (Dec 14, 2009):
Comment created by nicokaiser:
There is still an issue. You can reproduce it if you change the test case slightly to this:
The difference to the existing (and indeed working) test case is that the Cascader entity is persisted before the collection entries are added.
@doctrinebot commented on GitHub (Dec 14, 2009):
Comment created by @beberlei:
That is valid behaviour according to the lifecycle of an entity, persist gets cascaded right and only when ->persist() is called.
In the case you show, the two entities are also not persisted, because the cascade was already executed.
@doctrinebot commented on GitHub (Dec 14, 2009):
Comment created by nicokaiser:
From a technical point of view this is ok - but from an intuitive point of view I would think I can use persist whereever I want. So I can create an entity, persist it (so it gets written to the DB), make changes to it (like adding entities to its collection) and getting its saved (and the collection entities persisted) when I call flush().
So I suspect lifecycle events to be called whenever an entity is persisted. And in this case LifecycleCallbackTestEntity's are persisted automatically by flush() (and this is after the Cascader is persisted!), so lifecycle events should fire here.
@doctrinebot commented on GitHub (Dec 17, 2009):
Comment created by romanb:
I have a fix for this ready, however, I want to look into something else before committing. I'll address this over the weekend.
@doctrinebot commented on GitHub (Dec 18, 2009):
Comment created by romanb:
Should be fixed now.
@doctrinebot commented on GitHub (Dec 18, 2009):
Issue was closed with resolution "Fixed"