diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 828bd19..189a37f 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
+++ b/lib/Doctrine/ORM/UnitOfWork.php
@@ -1360,11 +1360,15 @@ class UnitOfWork implements PropertyChangedListener
                         if ( ! $assoc2->isCascadeMerge) {
                             $other = $class->reflFields[$name]->getValue($entity); //TODO: Just $prop->getValue($entity)?
                             if ($other !== null) {
-                                $targetClass = $this->_em->getClassMetadata($assoc2->targetEntityName);
-                                $id = $targetClass->getIdentifierValues($other);
-                                $proxy = $this->_em->getProxyFactory()->getProxy($assoc2->targetEntityName, $id);
-                                $prop->setValue($managedCopy, $proxy);
-                                $this->registerManaged($proxy, $id, array());
+                                if ($this->getEntityState($other, self::STATE_DETACHED) == self::STATE_MANAGED) {
+                                    $prop->setValue($managedCopy, $other);
+                                } else {
+                                    $targetClass = $this->_em->getClassMetadata($assoc2->targetEntityName);
+                                    $id = $targetClass->getIdentifierValues($other);
+                                    $proxy = $this->_em->getProxyFactory()->getProxy($assoc2->targetEntityName, $id);
+                                    $prop->setValue($managedCopy, $proxy);
+                                    $this->registerManaged($proxy, $id, array());
+                                }
                             }
                         }
                     } else {
diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php
new file mode 100644
index 0000000..2a34506
--- /dev/null
+++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php
@@ -0,0 +1,36 @@
+<?php
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+require_once __DIR__ . '/../../../TestInit.php';
+
+class DDC518Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+    public function setUp()
+    {
+        $this->useModelSet('cms');
+        parent::setUp();
+    }
+
+    public function testMergeWithRelatedNew()
+    {
+        $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
+        $article->text = "foo";
+        $article->topic = "bar";
+
+        $this->_em->persist($article);
+        $this->_em->flush();
+        $this->_em->detach($article);
+        $this->_em->clear();
+
+        $user = new \Doctrine\Tests\Models\CMS\CmsUser();
+        $user->username = "beberlei";
+        $user->name = "Benjamin Eberlei";
+        $user->status = "active";
+        $article->user = $user;
+
+        $this->_em->persist($user);
+        $managedArticle = $this->_em->merge($article);
+
+        $this->assertSame($article->user, $managedArticle->user);
+    }
+}
\ No newline at end of file
