DDC-3382: [GH-1419] With orphanRemoval, cannot delete and re-add entity #4176

Closed
opened 2026-01-22 14:36:44 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 10, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user c960657:

I have a one-to-many relation with orphanRemoval=true.

If I remove an entity from the related collection and add it back, the entity is removed from the database.

$employee = $company->getEmployees()->first();
$company->getEmployees()->removeElement($employee);
$company->getEmployees()->add($employee);

$em->persist($company);
$em->flush();
// Now $employee is deleted from the database.

The expected behaviour is to leave the entity in the database, because it was present in the PersistentCollection when $em->persist() was called.

Originally created by @doctrinebot on GitHub (Nov 10, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user c960657: I have a one-to-many relation with orphanRemoval=true. If I remove an entity from the related collection and add it back, the entity is removed from the database. ``` $employee = $company->getEmployees()->first(); $company->getEmployees()->removeElement($employee); $company->getEmployees()->add($employee); $em->persist($company); $em->flush(); // Now $employee is deleted from the database. ``` The expected behaviour is to leave the entity in the database, because it was present in the PersistentCollection when $em->persist() was called.
admin added the Bug label 2026-01-22 14:36:44 +01:00
admin closed this issue 2026-01-22 14:36:45 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 10, 2014):

@doctrinebot commented on GitHub (Nov 10, 2014): - is duplicated by [DDC-3765: [GH-1419] [DDC-3382] Allow orphan removal to be cancelled](http://www.doctrine-project.org/jira/browse/DDC-3765)
Author
Owner

@doctrinebot commented on GitHub (Nov 10, 2014):

Comment created by @ocramius:

This is expected behavior, and won't be changed for now.

@doctrinebot commented on GitHub (Nov 10, 2014): Comment created by @ocramius: This is expected behavior, and won't be changed for now.
Author
Owner

@doctrinebot commented on GitHub (Nov 10, 2014):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 10, 2014): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Feb 10, 2015):

Comment created by d.shashkin:

Is there any specific reason for this decision? Spent some time debugging because of this and I must say that such oddities are rather frustrating.

@doctrinebot commented on GitHub (Feb 10, 2015): Comment created by d.shashkin: Is there any specific reason for this decision? Spent some time debugging because of this and I must say that such oddities are rather frustrating.
Author
Owner

@doctrinebot commented on GitHub (Feb 10, 2015):

Comment created by @ocramius:

[~d.shashkin] we currently don't have an operation opposite to orphanRemoval

@doctrinebot commented on GitHub (Feb 10, 2015): Comment created by @ocramius: [~d.shashkin] we currently don't have an operation opposite to `orphanRemoval`
Author
Owner

@doctrinebot commented on GitHub (Jun 11, 2015):

Comment created by c960657:

I have made a PR with the suggested change. It is a very small fix, so I hope you will reconsider this suggestion in the light of this.

https://github.com/doctrine/doctrine2/pull/1419

@doctrinebot commented on GitHub (Jun 11, 2015): Comment created by c960657: I have made a PR with the suggested change. It is a very small fix, so I hope you will reconsider this suggestion in the light of this. https://github.com/doctrine/doctrine2/pull/1419
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1419] was merged:
https://github.com/doctrine/doctrine2/pull/1419

@doctrinebot commented on GitHub (Jun 16, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1419] was merged: https://github.com/doctrine/doctrine2/pull/1419
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4176