Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DDC-1383 - Proxy Generation in merge was flawed with inheritance

  • Loading branch information...
commit 0b3b4ecef68c9a83af9ba9fe457706e113ab14ba 1 parent 8e3fc30
@beberlei beberlei authored
View
14 lib/Doctrine/ORM/UnitOfWork.php
@@ -1471,11 +1471,17 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, $ass
if ($this->getEntityState($other, self::STATE_DETACHED) == self::STATE_MANAGED) {
$prop->setValue($managedCopy, $other);
} else {
+
$targetClass = $this->em->getClassMetadata($assoc2['targetEntity']);
- $id = $targetClass->getIdentifierValues($other);
- $proxy = $this->em->getProxyFactory()->getProxy($assoc2['targetEntity'], $id);
- $prop->setValue($managedCopy, $proxy);
- $this->registerManaged($proxy, $id, array());
+ $relatedId = $targetClass->getIdentifierValues($other);
+
+ if ($targetClass->subClasses) {
+ $entity = $this->em->find($targetClass->name, $relatedId);
+ } else {
+ $proxy = $this->em->getProxyFactory()->getProxy($assoc2['targetEntity'], $relatedId);
+ $prop->setValue($managedCopy, $proxy);
+ $this->registerManaged($proxy, $relatedId, array());
+ }
}
}
} else {
View
99 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+use Doctrine\ORM\UnitOfWork;
+
+require_once __DIR__ . '/../../../TestInit.php';
+
+/**
+ * @group DDC-1383
+ */
+class DDC1383Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ try {
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383AbstractEntity'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383Entity'),
+ ));
+ } catch(\Exception $ignored) {}
+ }
+
+ public function testFailingCase()
+ {
+ $parent = new DDC1383Entity();
+ $child = new DDC1383Entity();
+
+ $child->setReference($parent);
+
+ $this->_em->persist($parent);
+ $this->_em->persist($child);
+
+ $id = $child->getId();
+
+ $this->_em->flush();
+ $this->_em->clear();
+
+ // Try merging the parent entity
+ $child = $this->_em->merge($child);
+ $parent = $child->getReference();
+
+ // Parent is not instance of the abstract class
+ self::assertTrue($parent instanceof DDC1383AbstractEntity,
+ "Entity class is " . get_class($parent) . ', "DDC1383AbstractEntity" was expected');
+
+ // Parent is NOT instance of entity
+ self::assertTrue($parent instanceof DDC1383Entity,
+ "Entity class is " . get_class($parent) . ', "DDC1383Entity" was expected');
+ }
+}
+
+/**
+ * @Entity
+ * @InheritanceType("JOINED")
+ * @DiscriminatorColumn(name="discr", type="integer")
+ * @DiscriminatorMap({1 = "DDC1383Entity"})
+ */
+abstract class DDC1383AbstractEntity
+{
+ /**
+ * @Id
+ * @Column(type="integer")
+ * @GeneratedValue
+ */
+ protected $id;
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+}
+
+/**
+ * @Entity
+ */
+class DDC1383Entity extends DDC1383AbstractEntity
+{
+ /**
+ * @ManyToOne(targetEntity="DDC1383AbstractEntity")
+ */
+ protected $reference;
+
+ public function getReference()
+ {
+ return $this->reference;
+ }
+
+ public function setReference(DDC1383AbstractEntity $reference)
+ {
+ $this->reference = $reference;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.