File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
tests/Doctrine/ODM/MongoDB/Tests/Functional Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -646,6 +646,7 @@ public function clear()
646
646
}
647
647
648
648
if ($ this ->isOrphanRemovalEnabled ()) {
649
+ $ this ->initialize ();
649
650
foreach ($ this ->coll as $ element ) {
650
651
$ this ->uow ->scheduleOrphanRemoval ($ element );
651
652
}
Original file line number Diff line number Diff line change @@ -119,6 +119,31 @@ public function testOrphanRemovalOnReferenceManyUsingClear()
119
119
$ this ->assertNull ($ this ->getProfileRepository ()->find ($ profile2 ->id ), 'Profile 2 should have been removed ' );
120
120
}
121
121
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
+
122
147
public function testOrphanRemovalOnReferenceManyUsingClearAndAddingNewElements ()
123
148
{
124
149
$ profile1 = new OrphanRemovalProfile ();
You can’t perform that action at this time.
0 commit comments