DDC-731: Bi-directional cascade #900

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

Originally created by @doctrinebot on GitHub (Aug 5, 2010).

Jira issue originally created by user jasper:

Example:

/****
 * @Entity
 */
class Foo {

[...]

/****
 * @OneToOne( targetEntity = "Bar", cascade = {"remove"} )
 * @JoinColumn( name = "bar_id", onDelete = "CASCADE" )
 */
protected $bar;

[...]

}

In this case, Doctrine should cascade whenever a Bar is deleted. But, when you delete a Foo, it will also cascade the other way around, resulting in also deleting the Bar corresponding to this Foo. A possible solution is unsetting $bar before you remove it in the EntityManager.

Originally created by @doctrinebot on GitHub (Aug 5, 2010). Jira issue originally created by user jasper: Example: ``` /**** * @Entity */ class Foo { [...] /**** * @OneToOne( targetEntity = "Bar", cascade = {"remove"} ) * @JoinColumn( name = "bar_id", onDelete = "CASCADE" ) */ protected $bar; [...] } ``` In this case, Doctrine should cascade whenever a Bar is deleted. But, when you delete a Foo, it will also cascade the other way around, resulting in also deleting the Bar corresponding to this Foo. A possible solution is unsetting $bar before you remove it in the EntityManager.
admin added the Bug label 2026-01-22 12:54:37 +01:00
admin closed this issue 2026-01-22 12:54:40 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 5, 2010):

Comment created by @beberlei:

no, the mapping explicitly says If you delete Foo then also the Bar is deleted, i.e. {cascade="REMOVE"} leads to the behaviour Foo delete -> Bar delete.

@doctrinebot commented on GitHub (Aug 5, 2010): Comment created by @beberlei: no, the mapping explicitly says If you delete Foo then also the Bar is deleted, i.e. {cascade="REMOVE"} leads to the behaviour Foo delete -> Bar delete.
Author
Owner

@doctrinebot commented on GitHub (Aug 7, 2010):

Comment created by romanb:

You're using application-level and database-level cascades at the same time. This usually does not make sense. The behavior you describe is correct and is caused by the database foreign key constraint which is created with ON DELETE CASCADE.

@doctrinebot commented on GitHub (Aug 7, 2010): Comment created by romanb: You're using application-level and database-level cascades at the same time. This usually does not make sense. The behavior you describe is correct and is caused by the database foreign key constraint which is created with ON DELETE CASCADE.
Author
Owner

@doctrinebot commented on GitHub (Aug 7, 2010):

Issue was closed with resolution "Invalid"

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

No dependencies set.

Reference: doctrine/archived-orm#900