Skip to content

Commit 03bdd75

Browse files
authored
Merge pull request doctrine#1500 from akomm/fix/1497-1.0.x
Fix/1497 1.0.x
2 parents b1639e5 + d7e96d1 commit 03bdd75

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Doctrine/ODM/MongoDB/PersistentCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ public function clear()
646646
}
647647

648648
if ($this->isOrphanRemovalEnabled()) {
649+
$this->initialize();
649650
foreach ($this->coll as $element) {
650651
$this->uow->scheduleOrphanRemoval($element);
651652
}

tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ public function testOrphanRemovalOnReferenceManyUsingClear()
119119
$this->assertNull($this->getProfileRepository()->find($profile2->id), 'Profile 2 should have been removed');
120120
}
121121

122+
public function testOrphanRemovalOnReferenceManyUsingClearUninitialized()
123+
{
124+
$profile1 = new OrphanRemovalProfile();
125+
$profile2 = new OrphanRemovalProfile();
126+
127+
$user = new OrphanRemovalUser();
128+
$user->profileMany[] = $profile1;
129+
$user->profileMany[] = $profile2;
130+
$this->dm->persist($user);
131+
$this->dm->persist($profile1);
132+
$this->dm->persist($profile2);
133+
$this->dm->flush();
134+
135+
// Ensure profileMany is uninitialized
136+
$this->dm->detach($user);
137+
$user = $this->getUserRepository()->find($user->id);
138+
139+
$user->profileMany->clear();
140+
$this->dm->flush();
141+
$this->dm->clear();
142+
143+
$this->assertNull($this->getProfileRepository()->find($profile1->id), 'Profile 1 should have been removed');
144+
$this->assertNull($this->getProfileRepository()->find($profile2->id), 'Profile 2 should have been removed');
145+
}
146+
122147
public function testOrphanRemovalOnReferenceManyUsingClearAndAddingNewElements()
123148
{
124149
$profile1 = new OrphanRemovalProfile();

0 commit comments

Comments
 (0)