Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[DDC-2415] Fix CustomIdGenerator inheritance #653

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2013
  1. @FabioBatSilva

    Fix DDC-2415

    FabioBatSilva authored
This page is out of date. Refresh to see the latest.
View
4 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
@@ -103,6 +103,10 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
+ if ( ! empty($parent->customGeneratorDefinition)) {
+ $class->setCustomGeneratorDefinition($parent->customGeneratorDefinition);
+ }
+
if ($parent->isMappedSuperclass) {
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
}
View
106 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+require_once __DIR__ . '/../../../TestInit.php';
+
+use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\Id\AbstractIdGenerator;
+use Doctrine\ORM\Mapping\ClassMetadataInfo;
+use Doctrine\ORM\Mapping\Driver\StaticPHPDriver;
+
+/**
+ * @group DDC-2415
+ */
+class DDC2415Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->_em->getConfiguration()->setMetadataDriverImpl(new StaticPHPDriver(array()));
+
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ParentEntity'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ChildEntity'),
+ ));
+ }
+
+ public function testTicket()
+ {
+ $parentMetadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ParentEntity');
+ $childMetadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ChildEntity');
+
+ $this->assertEquals($parentMetadata->generatorType, $childMetadata->generatorType);
+ $this->assertEquals($parentMetadata->customGeneratorDefinition, $childMetadata->customGeneratorDefinition);
+ $this->assertEquals('Doctrine\Tests\ORM\Functional\Ticket\DDC2415Generator', $parentMetadata->customGeneratorDefinition['class']);
+
+ $e1 = new DDC2415ChildEntity("ChildEntity 1");
+ $e2 = new DDC2415ChildEntity("ChildEntity 2");
+
+ $this->_em->persist($e1);
+ $this->_em->persist($e2);
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $this->assertEquals(md5($e1->getName()), $e1->getId());
+ $this->assertEquals(md5($e2->getName()), $e2->getId());
+ }
+}
+
+class DDC2415ParentEntity
+{
+ protected $id;
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public static function loadMetadata(ClassMetadataInfo $metadata)
+ {
+ $metadata->mapField(array (
+ 'id' => true,
+ 'fieldName' => 'id',
+ 'type' => 'string',
+ ));
+
+ $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM);
+ $metadata->setCustomGeneratorDefinition(array(
+ 'class' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC2415Generator'
+ ));
+
+ $metadata->isMappedSuperclass = true;
+ }
+}
+
+class DDC2415ChildEntity extends DDC2415ParentEntity
+{
+ protected $name;
+
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public static function loadMetadata(ClassMetadataInfo $metadata)
+ {
+ $metadata->mapField(array (
+ 'fieldName' => 'name',
+ 'type' => 'string',
+ ));
+ }
+}
+
+class DDC2415Generator extends AbstractIdGenerator
+{
+ public function generate(EntityManager $em, $entity)
+ {
+ return md5($entity->getName());
+ }
+}
Something went wrong with that request. Please try again.