DDC-1218, DDC-1156 - Fixed bugs with mapped superclasses in inheritance hierachies
This commit is contained in:
parent
fe8b28a09f
commit
10b70df1af
@ -248,11 +248,13 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
|
|
||||||
// Move down the hierarchy of parent classes, starting from the topmost class
|
// Move down the hierarchy of parent classes, starting from the topmost class
|
||||||
$parent = null;
|
$parent = null;
|
||||||
|
$rootEntityFound = false;
|
||||||
$visited = array();
|
$visited = array();
|
||||||
foreach ($parentClasses as $className) {
|
foreach ($parentClasses as $className) {
|
||||||
if (isset($this->loadedMetadata[$className])) {
|
if (isset($this->loadedMetadata[$className])) {
|
||||||
$parent = $this->loadedMetadata[$className];
|
$parent = $this->loadedMetadata[$className];
|
||||||
if ( ! $parent->isMappedSuperclass) {
|
if ( ! $parent->isMappedSuperclass) {
|
||||||
|
$rootEntityFound = true;
|
||||||
array_unshift($visited, $className);
|
array_unshift($visited, $className);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -281,7 +283,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
throw MappingException::reflectionFailure($className, $e);
|
throw MappingException::reflectionFailure($className, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($parent && ! $parent->isMappedSuperclass) {
|
// If this class has a parent the id generator strategy is inherited.
|
||||||
|
// However this is only true if the hierachy of parents contains the root entity,
|
||||||
|
// if it consinsts of mapped superclasses these don't necessarily include the id field.
|
||||||
|
if ($parent && $rootEntityFound) {
|
||||||
if ($parent->isIdGeneratorSequence()) {
|
if ($parent->isIdGeneratorSequence()) {
|
||||||
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
||||||
} else if ($parent->isIdGeneratorTable()) {
|
} else if ($parent->isIdGeneratorTable()) {
|
||||||
@ -336,6 +341,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
$parent = $class;
|
$parent = $class;
|
||||||
|
|
||||||
if ( ! $class->isMappedSuperclass) {
|
if ( ! $class->isMappedSuperclass) {
|
||||||
|
$rootEntityFound = true;
|
||||||
array_unshift($visited, $className);
|
array_unshift($visited, $className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,32 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator);
|
$this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator);
|
||||||
$this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition);
|
$this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1156
|
||||||
|
* @group DDC-1218
|
||||||
|
*/
|
||||||
|
public function testSequenceDefinitionInHierachyWithSandwichMappedSuperclass()
|
||||||
|
{
|
||||||
|
$class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierachyD');
|
||||||
|
/* @var $class ClassMetadataInfo */
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator);
|
||||||
|
$this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1156
|
||||||
|
* @group DDC-1218
|
||||||
|
*/
|
||||||
|
public function testMultipleMappedSuperclasses()
|
||||||
|
{
|
||||||
|
$class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\MediumSuperclassEntity');
|
||||||
|
/* @var $class ClassMetadataInfo */
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator);
|
||||||
|
$this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransientBaseClass {
|
class TransientBaseClass {
|
||||||
@ -164,7 +190,8 @@ class EntitySubClass2 extends MappedSuperclassBase {
|
|||||||
abstract class HierachyBase
|
abstract class HierachyBase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Column(type="integer") @Id @GeneratedValue
|
* @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE")
|
||||||
|
* @SequenceGenerator(sequenceName="foo", initialValue="10")
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $id;
|
public $id;
|
||||||
@ -229,8 +256,25 @@ class SuperclassEntity extends SuperclassBase
|
|||||||
abstract class SuperclassBase
|
abstract class SuperclassBase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") @SequenceGenerator(sequenceName="foo", initialValue="10")
|
* @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE")
|
||||||
|
* @SequenceGenerator(sequenceName="foo", initialValue="10")
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $id;
|
public $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @MappedSuperclass
|
||||||
|
*/
|
||||||
|
abstract class MediumSuperclassBase extends SuperclassBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class MediumSuperclassEntity extends MediumSuperclassBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user