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()); + } +}