Merge pull request #1561 from deeky666/DDC-4006
[DDC-4006] Inherit ID generator strategy mapping from embeddables
This commit is contained in:
commit
9c5cea3e95
@ -157,19 +157,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
// However this is only true if the hierarchy of parents contains the root entity,
|
||||
// if it consists of mapped superclasses these don't necessarily include the id field.
|
||||
if ($parent && $rootEntityFound) {
|
||||
if ($parent->isIdGeneratorSequence()) {
|
||||
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
||||
} else if ($parent->isIdGeneratorTable()) {
|
||||
$class->tableGeneratorDefinition = $parent->tableGeneratorDefinition;
|
||||
}
|
||||
|
||||
if ($parent->generatorType) {
|
||||
$class->setIdGeneratorType($parent->generatorType);
|
||||
}
|
||||
|
||||
if ($parent->idGenerator) {
|
||||
$class->setIdGenerator($parent->idGenerator);
|
||||
}
|
||||
$this->inheritIdGeneratorMapping($class, $parent);
|
||||
} else {
|
||||
$this->completeIdGeneratorMapping($class);
|
||||
}
|
||||
@ -197,6 +185,10 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
$this->addNestedEmbeddedClasses($embeddableMetadata, $class, $property);
|
||||
}
|
||||
|
||||
if (! empty($embeddableMetadata->getIdentifier())) {
|
||||
$this->inheritIdGeneratorMapping($class, $embeddableMetadata);
|
||||
}
|
||||
|
||||
$class->inlineEmbeddable($property, $embeddableMetadata);
|
||||
|
||||
unset($this->embeddablesActiveNesting[$class->name]);
|
||||
@ -712,6 +704,29 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits the ID generator mapping from a parent class.
|
||||
*
|
||||
* @param ClassMetadataInfo $class
|
||||
* @param ClassMetadataInfo $parent
|
||||
*/
|
||||
private function inheritIdGeneratorMapping(ClassMetadataInfo $class, ClassMetadataInfo $parent)
|
||||
{
|
||||
if ($parent->isIdGeneratorSequence()) {
|
||||
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
||||
} elseif ($parent->isIdGeneratorTable()) {
|
||||
$class->tableGeneratorDefinition = $parent->tableGeneratorDefinition;
|
||||
}
|
||||
|
||||
if ($parent->generatorType) {
|
||||
$class->setIdGeneratorType($parent->generatorType);
|
||||
}
|
||||
|
||||
if ($parent->idGenerator) {
|
||||
$class->setIdGenerator($parent->idGenerator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
14
tests/Doctrine/Tests/Models/DDC4006/DDC4006User.php
Normal file
14
tests/Doctrine/Tests/Models/DDC4006/DDC4006User.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC4006;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC4006User
|
||||
{
|
||||
/**
|
||||
* @Embedded(class="DDC4006UserId")
|
||||
*/
|
||||
private $id;
|
||||
}
|
16
tests/Doctrine/Tests/Models/DDC4006/DDC4006UserId.php
Normal file
16
tests/Doctrine/Tests/Models/DDC4006/DDC4006UserId.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC4006;
|
||||
|
||||
/**
|
||||
* @Embeddable
|
||||
*/
|
||||
class DDC4006UserId
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @GeneratedValue("IDENTITY")
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
}
|
@ -309,7 +309,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertEquals('parent-id', $user['joinColumns'][0]['name']);
|
||||
$this->assertEquals('group-id', $user['joinColumns'][0]['referencedColumnName']);
|
||||
|
||||
|
||||
|
||||
// Address Class Metadata
|
||||
$this->assertTrue($addressMetadata->fieldMappings['id']['quoted']);
|
||||
$this->assertTrue($addressMetadata->fieldMappings['zip']['quoted']);
|
||||
@ -327,11 +327,11 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
// User Class Metadata
|
||||
$this->assertTrue($userMetadata->fieldMappings['id']['quoted']);
|
||||
$this->assertTrue($userMetadata->fieldMappings['name']['quoted']);
|
||||
|
||||
|
||||
$this->assertEquals('user-id', $userMetadata->fieldMappings['id']['columnName']);
|
||||
$this->assertEquals('user-name', $userMetadata->fieldMappings['name']['columnName']);
|
||||
|
||||
|
||||
|
||||
$address = $userMetadata->associationMappings['address'];
|
||||
$this->assertTrue($address['joinColumns'][0]['quoted']);
|
||||
$this->assertEquals('address-id', $address['joinColumns'][0]['name']);
|
||||
@ -423,6 +423,21 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$cmf->getMetadataFor($metadata->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-4006
|
||||
*/
|
||||
public function testInheritsIdGeneratorMappingFromEmbeddable()
|
||||
{
|
||||
$cmf = new ClassMetadataFactory();
|
||||
$driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/DDC4006/'));
|
||||
$em = $this->_createEntityManager($driver);
|
||||
$cmf->setEntityManager($em);
|
||||
|
||||
$userMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\DDC4006\DDC4006User');
|
||||
|
||||
$this->assertTrue($userMetadata->isIdGeneratorIdentity());
|
||||
}
|
||||
}
|
||||
|
||||
/* Test subject class with overridden factory method for mocking purposes */
|
||||
|
Loading…
x
Reference in New Issue
Block a user