DDC-3765: [GH-1419] [DDC-3382] Allow orphan removal to be cancelled #4616

Closed
opened 2026-01-22 14:46:03 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 11, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of c960657:

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

Message:

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.

This has previously been suggested in [DDC-3382](http://www.doctrine-project.org/jira/browse/[DDC-3382]%28http://www.doctrine-project.org/jira/browse/DDC-3382%29), but it was rejected. This PR shows how small a change it is, so I hope the suggestion will be reconsidered in the light of this.

Originally created by @doctrinebot on GitHub (Jun 11, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of c960657: Url: https://github.com/doctrine/doctrine2/pull/1419 Message: 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. ``` PHP $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. This has previously been suggested in [[DDC-3382](http://www.doctrine-project.org/jira/browse/DDC-3382)](http://www.doctrine-project.org/jira/browse/[DDC-3382]%28http://www.doctrine-project.org/jira/browse/DDC-3382%29), but it was rejected. This PR shows how small a change it is, so I hope the suggestion will be reconsidered in the light of this.
admin added the Bug label 2026-01-22 14:46:03 +01:00
admin closed this issue 2026-01-22 14:46:03 +01:00
Author
Owner

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

@doctrinebot commented on GitHub (Jun 11, 2015): - duplicates [DDC-3382: [GH-1419] With orphanRemoval, cannot delete and re-add entity ](http://www.doctrine-project.org/jira/browse/DDC-3382)
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#4616