DDC-345: Lifecycle callbacks break properties on cascade=persist #427

Closed
opened 2026-01-22 12:37:54 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 17, 2010).

Jira issue originally created by user nicokaiser:

When I try to create an association entity for a ManyToMany association (e.g. Users, Groups and an associating Membership entity that holds some more properties than just userId and groupId), I use cascade={"persist"} in the @OneToMany annotations for Users and Groups.

Membership also has Lifecycle callbacks (e.g. for setting an "updated" property). Now when I add the Membership object to the User and Group objects, its Lifecycle callbacks are called more than one time, and when it's called the second time, all properties but the ones set by the callback function are unset.

$membership = new \Entity\Membership;
$membership->Group = $group;
$membership->User = $user;

$user->Memberships->add($membership);  // $membership is persisted once
$group->Memberships->add($membership); // $membership is persieted a second time

$em->flush();

Complete example: http://pastie.org/828718

Script output: http://pastie.org/828727

Originally created by @doctrinebot on GitHub (Feb 17, 2010). Jira issue originally created by user nicokaiser: When I try to create an association entity for a ManyToMany association (e.g. Users, Groups and an associating Membership entity that holds some more properties than just userId and groupId), I use cascade={"persist"} in the @OneToMany annotations for Users and Groups. Membership also has Lifecycle callbacks (e.g. for setting an "updated" property). Now when I add the Membership object to the User and Group objects, its Lifecycle callbacks are called more than one time, and when it's called the second time, all properties but the ones set by the callback function are unset. ``` $membership = new \Entity\Membership; $membership->Group = $group; $membership->User = $user; $user->Memberships->add($membership); // $membership is persisted once $group->Memberships->add($membership); // $membership is persieted a second time $em->flush(); ``` Complete example: http://pastie.org/828718 Script output: http://pastie.org/828727
admin added the Bug label 2026-01-22 12:37:54 +01:00
admin closed this issue 2026-01-22 12:37:54 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 17, 2010):

Comment created by nicokaiser:

Maybe this is related to DDC-74?

@doctrinebot commented on GitHub (Feb 17, 2010): Comment created by nicokaiser: Maybe this is related to [DDC-74](http://www.doctrine-project.org/jira/browse/DDC-74)?
Author
Owner

@doctrinebot commented on GitHub (Feb 23, 2010):

Comment created by romanb:

Should be fixed now, was a state issue. Thanks for the full example, that made it easy to create a test case.

@doctrinebot commented on GitHub (Feb 23, 2010): Comment created by romanb: Should be fixed now, was a state issue. Thanks for the full example, that made it easy to create a test case.
Author
Owner

@doctrinebot commented on GitHub (Feb 23, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 23, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#427