mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1879: Orphans are neither nulled nor removed when merging a graph of detached entities #2370
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 (Jun 18, 2012).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user systho:
When merging a graph of detached entities, the created entitied are created and the updated entities are updated but the non-present entities (which exist in the database but are not in the graph) are neither removed nor have them their association column nullified.
Example :
In my code I have 2 entities : Parent and Child. There is a OneToMany(cascade={"all"}, orphanRemoval=true) relation defined in Parent.
In my database I have a Parent row with an id of 1, which has 3 Children with ids 1,2,3.
When I write the following code, I expect the Parent with id 1 and the Child with id 2 to be updated, a new Child to be created and the Child with id 1 and 3 to be deleted.
The objects I expect to be created and updated have the correct behaviour but the old children are not touched, they are still present in the database.
@doctrinebot commented on GitHub (Jan 23, 2013):
Comment created by @ocramius:
I don't think this is valid. Orphan removal scheduling is handled only when an unit of work is available.
What's the state of
$dinnerbefore your example? Can youvar_dumpit?@MatthiasKuehneEllerhold commented on GitHub (Nov 3, 2017):
@Ocramius I've ran into the same problem today. So I guess this issue is still relevant?
I guess
$dinnerwas meant to be$parentin systho example?$parenthas ID 1 and anArrayCollection(I guess?) with just the two childs:Our expections are:
What I've tried:
But the obsolete children were never deleted from the database.
I hooked up an SQL query logger to doctrine and there are only
UPDATE&INSERTqueries in it, theDELETEqueries are missing.Mapping annotation of
$childrenin classParent:Mapping annotation of
$parentin classChild:I'm using doctrine/orm in a zend-expressive project with these versions:
@lcobucci commented on GitHub (Nov 26, 2017):
@MatthiasKuehneEllerhold could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.
You can find examples on
388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket@MatthiasKuehneEllerhold commented on GitHub (Nov 27, 2017):
I've opened a PR with a failing test case for this: https://github.com/doctrine/doctrine2/pull/6850 .
@Liiva commented on GitHub (Nov 19, 2018):
I'm running into the same issue. In the PR it is mentioned this might be fixed in version 2.6 but as we're using 2.7.1 I assume this is not the case. Any updates on this issue?
I've created a separate repo with a reproducible case here.