commit
e6b99c2059
@ -203,9 +203,10 @@
|
|||||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
|
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
|
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
|
||||||
<xs:attribute name="type" type="xs:NMTOKEN" use="required" />
|
<xs:attribute name="type" type="xs:NMTOKEN"/>
|
||||||
<xs:attribute name="field-name" type="xs:NMTOKEN" />
|
<xs:attribute name="field-name" type="xs:NMTOKEN" />
|
||||||
<xs:attribute name="length" type="xs:NMTOKEN" />
|
<xs:attribute name="length" type="xs:NMTOKEN" />
|
||||||
|
<xs:attribute name="column-definition" type="xs:string" />
|
||||||
<xs:anyAttribute namespace="##other"/>
|
<xs:anyAttribute namespace="##other"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
@ -278,6 +279,7 @@
|
|||||||
<xs:attribute name="type" type="xs:NMTOKEN" />
|
<xs:attribute name="type" type="xs:NMTOKEN" />
|
||||||
<xs:attribute name="column" type="xs:NMTOKEN" />
|
<xs:attribute name="column" type="xs:NMTOKEN" />
|
||||||
<xs:attribute name="association-key" type="xs:boolean" default="false" />
|
<xs:attribute name="association-key" type="xs:boolean" default="false" />
|
||||||
|
<xs:attribute name="column-definition" type="xs:string" />
|
||||||
<xs:anyAttribute namespace="##other"/>
|
<xs:anyAttribute namespace="##other"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
|
@ -33,4 +33,6 @@ final class DiscriminatorColumn implements Annotation
|
|||||||
public $length;
|
public $length;
|
||||||
/** @var mixed */
|
/** @var mixed */
|
||||||
public $fieldName; // field name used in non-object hydration (array/scalar)
|
public $fieldName; // field name used in non-object hydration (array/scalar)
|
||||||
|
/** @var string */
|
||||||
|
public $columnDefinition;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,8 @@ class AnnotationDriver implements Driver
|
|||||||
$metadata->setDiscriminatorColumn(array(
|
$metadata->setDiscriminatorColumn(array(
|
||||||
'name' => $discrColumnAnnot->name,
|
'name' => $discrColumnAnnot->name,
|
||||||
'type' => $discrColumnAnnot->type,
|
'type' => $discrColumnAnnot->type,
|
||||||
'length' => $discrColumnAnnot->length
|
'length' => $discrColumnAnnot->length,
|
||||||
|
'columnDefinition' => $discrColumnAnnot->columnDefinition
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||||
|
@ -99,9 +99,10 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
if (isset($xmlRoot->{'discriminator-column'})) {
|
if (isset($xmlRoot->{'discriminator-column'})) {
|
||||||
$discrColumn = $xmlRoot->{'discriminator-column'};
|
$discrColumn = $xmlRoot->{'discriminator-column'};
|
||||||
$metadata->setDiscriminatorColumn(array(
|
$metadata->setDiscriminatorColumn(array(
|
||||||
'name' => (string)$discrColumn['name'],
|
'name' => isset($discrColumn['name']) ? (string)$discrColumn['name'] : null,
|
||||||
'type' => (string)$discrColumn['type'],
|
'type' => isset($discrColumn['type']) ? (string)$discrColumn['type'] : null,
|
||||||
'length' => (string)$discrColumn['length']
|
'length' => isset($discrColumn['length']) ? (string)$discrColumn['length'] : null,
|
||||||
|
'columnDefinition' => isset($discrColumn['column-definition']) ? (string)$discrColumn['column-definition'] : null
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||||
|
@ -96,9 +96,10 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
if (isset($element['discriminatorColumn'])) {
|
if (isset($element['discriminatorColumn'])) {
|
||||||
$discrColumn = $element['discriminatorColumn'];
|
$discrColumn = $element['discriminatorColumn'];
|
||||||
$metadata->setDiscriminatorColumn(array(
|
$metadata->setDiscriminatorColumn(array(
|
||||||
'name' => $discrColumn['name'],
|
'name' => isset($discrColumn['name']) ? (string)$discrColumn['name'] : null,
|
||||||
'type' => $discrColumn['type'],
|
'type' => isset($discrColumn['type']) ? (string)$discrColumn['type'] : null,
|
||||||
'length' => $discrColumn['length']
|
'length' => isset($discrColumn['length']) ? (string)$discrColumn['length'] : null,
|
||||||
|
'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string)$discrColumn['columnDefinition'] : null
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
|
||||||
|
@ -288,11 +288,16 @@ class SchemaTool
|
|||||||
$discrColumn['length'] = 255;
|
$discrColumn['length'] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->addColumn(
|
$options = array(
|
||||||
$discrColumn['name'],
|
'length' => isset($discrColumn['length']) ? $discrColumn['length'] : null,
|
||||||
$discrColumn['type'],
|
'notnull' => true
|
||||||
array('length' => $discrColumn['length'], 'notnull' => true)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($discrColumn['columnDefinition'])) {
|
||||||
|
$options['columnDefinition'] = $discrColumn['columnDefinition'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->addColumn($discrColumn['name'], $discrColumn['type'], $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -434,6 +434,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertEquals('NAME', $class->columnNames['name']);
|
$this->assertEquals('NAME', $class->columnNames['name']);
|
||||||
$this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']);
|
$this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-807
|
||||||
|
* @group DDC-553
|
||||||
|
*/
|
||||||
|
public function testDiscriminatorColumnDefinition()
|
||||||
|
{
|
||||||
|
$class = $this->createClassMetadata(__NAMESPACE__ . '\DDC807Entity');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('columnDefinition', $class->discriminatorColumn);
|
||||||
|
$this->assertArrayHasKey('name', $class->discriminatorColumn);
|
||||||
|
|
||||||
|
$this->assertEquals("ENUM('ONE','TWO')", $class->discriminatorColumn['columnDefinition']);
|
||||||
|
$this->assertEquals("dtype", $class->discriminatorColumn['name']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -724,6 +739,42 @@ class DDC1170Entity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @InheritanceType("SINGLE_TABLE")
|
||||||
|
* @DiscriminatorMap({"ONE" = "DDC807SubClasse1", "TWO" = "DDC807SubClasse2"})
|
||||||
|
* @DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
|
||||||
|
*/
|
||||||
|
class DDC807Entity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="NONE")
|
||||||
|
**/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
public static function loadMetadata(ClassMetadataInfo $metadata)
|
||||||
|
{
|
||||||
|
$metadata->mapField(array(
|
||||||
|
'id' => true,
|
||||||
|
'fieldName' => 'id',
|
||||||
|
));
|
||||||
|
|
||||||
|
$metadata->setDiscriminatorColumn(array(
|
||||||
|
'name' => "dtype",
|
||||||
|
'type' => "string",
|
||||||
|
'columnDefinition' => "ENUM('ONE','TWO')"
|
||||||
|
));
|
||||||
|
|
||||||
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DDC807SubClasse1 {}
|
||||||
|
class DDC807SubClasse2 {}
|
||||||
|
|
||||||
class Address {}
|
class Address {}
|
||||||
class Phonenumber {}
|
class Phonenumber {}
|
||||||
class Group {}
|
class Group {}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
|
||||||
|
$metadata->mapField(array(
|
||||||
|
'id' => true,
|
||||||
|
'fieldName' => 'id',
|
||||||
|
));
|
||||||
|
|
||||||
|
$metadata->setDiscriminatorColumn(array(
|
||||||
|
'name' => "dtype",
|
||||||
|
'columnDefinition' => "ENUM('ONE','TWO')"
|
||||||
|
));
|
||||||
|
|
||||||
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
|
@ -0,0 +1,20 @@
|
|||||||
|
<?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\DDC807Entity" inheritance-type="SINGLE_TABLE">
|
||||||
|
<id name="id">
|
||||||
|
<generator strategy="NONE"/>
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<discriminator-column name="dtype" column-definition="ENUM('ONE','TWO')"/>
|
||||||
|
|
||||||
|
<discriminator-map>
|
||||||
|
<discriminator-mapping value="ONE" class="DDC807SubClasse1" />
|
||||||
|
<discriminator-mapping value="TWO" class="DDC807SubClasse1" />
|
||||||
|
</discriminator-map>
|
||||||
|
</entity>
|
||||||
|
|
||||||
|
</doctrine-mapping>
|
@ -0,0 +1,13 @@
|
|||||||
|
Doctrine\Tests\ORM\Mapping\DDC807Entity:
|
||||||
|
type: entity
|
||||||
|
inheritanceType: SINGLE_TABLE
|
||||||
|
discriminatorMap:
|
||||||
|
ONE: DDC807SubClasse1
|
||||||
|
TWO: DDC807SubClasse2
|
||||||
|
discriminatorColumn:
|
||||||
|
name: dtype
|
||||||
|
columnDefinition: ENUM('ONE','TWO')
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
generator:
|
||||||
|
strategy: NONE
|
Loading…
Reference in New Issue
Block a user