Details
-
Type:
Bug
-
Status:
Awaiting Feedback
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.2.2
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
-
Environment:Doctrine 2.2.2
PHP 5.3.10 with Suhosin-Patch
mysql Ver 14.14 Distrib 5.5.15, for osx10.7
Mac OS X 10.7 Lion
Description
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.
$parent = new Parent(); $parent->id = 1 // detached entity $existing_child = new Child(); $child->id = 2 // detached entity $new_child = new Child(); // new entity $dinner->addChild($existing_child); $dinner->addChild($new_child); $em->merge($dinner); $em->flush();
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.
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 `$dinner` before your example? Can you `var_dump` it?