Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixed DDC1778 #336

Merged
merged 1 commit into from about 2 years ago

2 participants

Tim Nagel Guilherme Blanco
Guilherme Blanco guilhermeblanco merged commit c02ac65 into from April 16, 2012
Guilherme Blanco guilhermeblanco closed this April 16, 2012
Benjamin Eberlei beberlei referenced this pull request from a commit April 16, 2012
Tim Nagel Cherry-pick GH-336 into 2.2 159b6f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 16, 2012
Tim Nagel Fixed DDC1778 6cbdf53
This page is out of date. Refresh to see the latest.
8  lib/Doctrine/ORM/PersistentCollection.php
@@ -389,6 +389,7 @@ public function remove($key)
389 389
 
390 390
         if ($this->association !== null &&
391 391
             $this->association['type'] & ClassMetadata::TO_MANY &&
  392
+            $this->owner &&
392 393
             $this->association['orphanRemoval']) {
393 394
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($removed);
394 395
         }
@@ -427,6 +428,7 @@ public function removeElement($element)
427 428
 
428 429
         if ($this->association !== null &&
429 430
             $this->association['type'] & ClassMetadata::TO_MANY &&
  431
+            $this->owner &&
430 432
             $this->association['orphanRemoval']) {
431 433
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($element);
432 434
         }
@@ -631,7 +633,9 @@ public function clear()
631 633
 
632 634
         $uow = $this->em->getUnitOfWork();
633 635
 
634  
-        if ($this->association['type'] & ClassMetadata::TO_MANY && $this->association['orphanRemoval']) {
  636
+        if ($this->association['type'] & ClassMetadata::TO_MANY &&
  637
+            $this->association['orphanRemoval'] &&
  638
+            $this->owner) {
635 639
             // we need to initialize here, as orphan removal acts like implicit cascadeRemove,
636 640
             // hence for event listeners we need the objects in memory.
637 641
             $this->initialize();
@@ -783,7 +787,7 @@ public function __clone()
783 787
         }
784 788
 
785 789
         $this->snapshot = array();
786  
-        
  790
+
787 791
         $this->changed();
788 792
     }
789 793
 }
74  tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php
... ...
@@ -0,0 +1,74 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\Tests\ORM\Functional\Ticket;
  4
+
  5
+use Doctrine\Tests\Models\CMS\CmsUser;
  6
+use Doctrine\Tests\Models\CMS\CmsPhonenumber;
  7
+
  8
+/**
  9
+ * @group DDC-1778
  10
+ */
  11
+class DDC1778Test extends \Doctrine\Tests\OrmFunctionalTestCase
  12
+{
  13
+    private $user;
  14
+    private $phone;
  15
+
  16
+    public function setUp()
  17
+    {
  18
+        $this->useModelSet('cms');
  19
+        parent::setUp();
  20
+
  21
+        $this->user = new CmsUser();
  22
+        $this->user->username = "beberlei";
  23
+        $this->user->name = "Benjamin";
  24
+        $this->user->status = "active";
  25
+
  26
+        $this->phone = new CmsPhoneNumber();
  27
+        $this->phone->phonenumber = '0123456789';
  28
+        $this->user->addPhoneNumber($this->phone);
  29
+
  30
+        $this->_em->persist($this->user);
  31
+        $this->_em->persist($this->phone);
  32
+        $this->_em->flush();
  33
+        $this->_em->clear();
  34
+
  35
+        $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
  36
+        $this->phone = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', $this->phone->phonenumber);
  37
+    }
  38
+
  39
+    public function testClear()
  40
+    {
  41
+        $clonedNumbers = clone $this->user->getPhonenumbers();
  42
+        $clonedNumbers->clear();
  43
+        $this->_em->flush();
  44
+        $this->_em->clear();
  45
+
  46
+        $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
  47
+
  48
+        $this->assertCount(1, $this->user->getPhonenumbers());
  49
+    }
  50
+
  51
+    public function testRemove()
  52
+    {
  53
+        $clonedNumbers = clone $this->user->getPhonenumbers();
  54
+        $clonedNumbers->remove(0);
  55
+        $this->_em->flush();
  56
+        $this->_em->clear();
  57
+
  58
+        $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
  59
+
  60
+        $this->assertCount(1, $this->user->getPhonenumbers());
  61
+    }
  62
+
  63
+    public function testRemoveElement()
  64
+    {
  65
+        $clonedNumbers = clone $this->user->getPhonenumbers();
  66
+        $clonedNumbers->removeElement($this->phone);
  67
+        $this->_em->flush();
  68
+        $this->_em->clear();
  69
+
  70
+        $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
  71
+
  72
+        $this->assertCount(1, $this->user->getPhonenumbers());
  73
+    }
  74
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.