From 56ea4872cafd173b9dcdf287c9f26d2781bbda8e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 15 Jan 2012 15:48:44 +0100 Subject: [PATCH] DDC-1594 - Fix problem with merge and an existing managed proxy instance. --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++ .../ORM/Functional/Ticket/DDC1594Test.php | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 6142ca958..49b3fcd34 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1685,6 +1685,10 @@ class UnitOfWork implements PropertyChangedListener $class->setIdentifierValues($managedCopy, $id); $this->persistNew($class, $managedCopy); + } else { + if ($managedCopy instanceof Proxy && ! $managedCopy->__isInitialized__) { + $managedCopy->__load(); + } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php new file mode 100644 index 000000000..b8dec401c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php @@ -0,0 +1,45 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testIssue() + { + $user = new CmsUser(); + $user->status = 'foo'; + $user->username = 'foo'; + $user->name = 'foo'; + + $this->_em->persist($user); + $this->_em->flush(); + + $this->_em->clear(); + $detachedUser = clone $user; + $detachedUser->name = 'bar'; + $detachedUser->status = 'bar'; + + $newUser = $this->_em->getReference(get_class($user), $user->id); + + $mergedUser = $this->_em->merge($detachedUser); + + $this->assertNotSame($mergedUser, $detachedUser); + $this->assertEquals('bar', $detachedUser->getName()); + $this->assertEquals('bar', $mergedUser->getName()); + } +}