Modified class metadata factory to have entity tables inherit indexes from mapped superclasses
This commit is contained in:
parent
ec6781954a
commit
17ec1aab77
2 changed files with 65 additions and 0 deletions
|
@ -175,6 +175,24 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||||
$class->setPrimaryTable($parent->table);
|
$class->setPrimaryTable($parent->table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($parent && $parent->isMappedSuperclass) {
|
||||||
|
//Copy the table indices from the parent
|
||||||
|
|
||||||
|
$indexTypes = array ('uniqueConstraints', 'indexes');
|
||||||
|
|
||||||
|
foreach ($indexTypes as $indexType) {
|
||||||
|
if (isset($parent->table[$indexType])) {
|
||||||
|
foreach ($parent->table[$indexType] as $indexName => $index) {
|
||||||
|
if (isset($class->table[$indexType][$indexName])) {
|
||||||
|
continue; // Let the inheriting table override indices
|
||||||
|
}
|
||||||
|
|
||||||
|
$class->table[$indexType][$indexName] = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($parent && $parent->cache) {
|
if ($parent && $parent->cache) {
|
||||||
$class->cache = $parent->cache;
|
$class->cache = $parent->cache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Doctrine\Tests\ORM\Mapping;
|
namespace Doctrine\Tests\ORM\Mapping;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
|
||||||
class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
@ -167,6 +168,22 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure indexes are inherited from the mapped superclass.
|
||||||
|
*
|
||||||
|
* @group DDC-3418
|
||||||
|
*/
|
||||||
|
public function testMappedSuperclassIndex()
|
||||||
|
{
|
||||||
|
$class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass');
|
||||||
|
/* @var $class ClassMetadataInfo */
|
||||||
|
|
||||||
|
$this->assertTrue(isset($class->fieldMappings['mapped1']));
|
||||||
|
$this->assertTrue(isset($class->table['uniqueConstraints']['IDX_NAME_INDEX']));
|
||||||
|
$this->assertTrue(isset($class->table['uniqueConstraints']['IDX_MAPPED1_INDEX']));
|
||||||
|
$this->assertTrue(isset($class->table['indexes']['IDX_MAPPED2_INDEX']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransientBaseClass {
|
class TransientBaseClass {
|
||||||
|
@ -206,6 +223,36 @@ class EntitySubClass2 extends MappedSuperclassBase {
|
||||||
private $name;
|
private $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @MappedSuperclass
|
||||||
|
*
|
||||||
|
* @Table(
|
||||||
|
* uniqueConstraints={@UniqueConstraint(name="IDX_MAPPED1_INDEX",columns={"mapped1"})},
|
||||||
|
* indexes={@Index(name="IDX_MAPPED2_INDEX", columns={"mapped2"})}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class MappedSuperclassBaseIndex {
|
||||||
|
/** @Column(type="string") */
|
||||||
|
private $mapped1;
|
||||||
|
/** @Column(type="string") */
|
||||||
|
private $mapped2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*
|
||||||
|
* @Table(
|
||||||
|
* uniqueConstraints={@UniqueConstraint(name="IDX_NAME_INDEX",columns={"name"})}
|
||||||
|
* )
|
||||||
|
* */
|
||||||
|
class EntityIndexSubClass extends MappedSuperclassBaseIndex
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="integer") */
|
||||||
|
private $id;
|
||||||
|
/** @Column(type="string") */
|
||||||
|
private $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
* @InheritanceType("SINGLE_TABLE")
|
* @InheritanceType("SINGLE_TABLE")
|
||||||
|
|
Loading…
Add table
Reference in a new issue