DDC-514 - Implemented default for discriminator column
This commit is contained in:
parent
8b766b6c92
commit
8f80c94923
@ -179,6 +179,8 @@ class AnnotationDriver implements Driver
|
||||
'type' => $discrColumnAnnot->type,
|
||||
'length' => $discrColumnAnnot->length
|
||||
));
|
||||
} else {
|
||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||
}
|
||||
|
||||
// Evaluate DiscriminatorMap annotation
|
||||
|
@ -87,6 +87,8 @@ class XmlDriver extends AbstractFileDriver
|
||||
'type' => (string)$discrColumn['type'],
|
||||
'length' => (string)$discrColumn['length']
|
||||
));
|
||||
} else {
|
||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||
}
|
||||
|
||||
// Evaluate <discriminator-map...>
|
||||
|
@ -79,6 +79,8 @@ class YamlDriver extends AbstractFileDriver
|
||||
'type' => $discrColumn['type'],
|
||||
'length' => $discrColumn['length']
|
||||
));
|
||||
} else {
|
||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||
}
|
||||
|
||||
// Evaluate discriminatorMap
|
||||
|
@ -13,17 +13,22 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
abstract protected function _loadDriver();
|
||||
|
||||
public function testLoadMapping()
|
||||
public function createClassMetadata($entityClassName)
|
||||
{
|
||||
$className = 'Doctrine\Tests\ORM\Mapping\User';
|
||||
$mappingDriver = $this->_loadDriver();
|
||||
|
||||
$class = new ClassMetadata($className);
|
||||
$mappingDriver->loadMetadataForClass($className, $class);
|
||||
$class = new ClassMetadata($entityClassName);
|
||||
$mappingDriver->loadMetadataForClass($entityClassName, $class);
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function testLoadMapping()
|
||||
{
|
||||
$entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
|
||||
return $this->createClassMetadata($entityClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testLoadMapping
|
||||
* @param ClassMetadata $class
|
||||
@ -269,6 +274,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-514
|
||||
*/
|
||||
public function testDiscriminatorColumnDefaults()
|
||||
{
|
||||
if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
|
||||
$this->markTestSkipped('PHP Mapping Drivers have no defaults.');
|
||||
}
|
||||
|
||||
$class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
|
||||
|
||||
$this->assertEquals(
|
||||
array('name' => 'dtype', 'type' => 'string', 'length' => 255, 'fieldName' => 'dtype'),
|
||||
$class->discriminatorColumn
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,3 +481,39 @@ class User
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("SINGLE_TABLE")
|
||||
* @DiscriminatorMap({"cat" = "Cat", "dog" = "Dog"})
|
||||
*/
|
||||
abstract class Animal
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="string") @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
public static function loadMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class Cat extends Animal
|
||||
{
|
||||
public static function loadMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class Dog extends Animal
|
||||
{
|
||||
public static function loadMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\Animal" inheritance-type="SINGLE_TABLE">
|
||||
<discriminator-map>
|
||||
<discriminator-mapping value="cat" class="Cat" />
|
||||
<discriminator-mapping value="dog" class="Dog" />
|
||||
</discriminator-map>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
@ -0,0 +1,6 @@
|
||||
Doctrine\Tests\ORM\Mapping\Animal:
|
||||
type: entity
|
||||
inheritanceType: SINGLE_TABLE
|
||||
discriminatorMap:
|
||||
cat: Cat
|
||||
dog: Dog
|
Loading…
Reference in New Issue
Block a user