File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -564,7 +564,9 @@ public function clear()
564564 if ($ this ->association ->isOwningSide () && $ this ->owner ) {
565565 $ this ->changed ();
566566
567- $ uow ->scheduleCollectionDeletion ($ this );
567+ if ($ this ->em ->getClassMetadata (get_class ($ this ->owner ))->changeTrackingPolicy !== ChangeTrackingPolicy::DEFERRED_EXPLICIT ) {
568+ $ uow ->scheduleCollectionDeletion ($ this );
569+ }
568570
569571 $ this ->takeSnapshot ();
570572 }
Original file line number Diff line number Diff line change 55namespace Doctrine \Tests \ORM ;
66
77use Doctrine \Common \Collections \ArrayCollection ;
8+ use Doctrine \ORM \Mapping \ChangeTrackingPolicy ;
89use Doctrine \ORM \PersistentCollection ;
910use Doctrine \ORM \UnitOfWork ;
1011use Doctrine \Tests \Mocks \ConnectionMock ;
@@ -269,4 +270,25 @@ public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsW
269270 self ::assertTrue ($ this ->collection ->isInitialized ());
270271 self ::assertFalse ($ this ->collection ->isDirty ());
271272 }
273+
274+ public function testModifyUOWForDeferredImplicitOwnerOnClear () : void
275+ {
276+ $ unitOfWork = $ this ->createMock (UnitOfWork::class);
277+ $ unitOfWork ->expects (self ::once ())->method ('scheduleCollectionDeletion ' );
278+ $ this ->emMock ->setUnitOfWork ($ unitOfWork );
279+
280+ $ this ->collection ->clear ();
281+ }
282+
283+ public function testDoNotModifyUOWForDeferredExplicitOwnerOnClear () : void
284+ {
285+ $ unitOfWork = $ this ->createMock (UnitOfWork::class);
286+ $ unitOfWork ->expects (self ::never ())->method ('scheduleCollectionDeletion ' );
287+ $ this ->emMock ->setUnitOfWork ($ unitOfWork );
288+
289+ $ classMetaData = $ this ->emMock ->getClassMetadata (ECommerceCart::class);
290+ $ classMetaData ->setChangeTrackingPolicy (ChangeTrackingPolicy::DEFERRED_EXPLICIT );
291+
292+ $ this ->collection ->clear ();
293+ }
272294}
You can’t perform that action at this time.
0 commit comments