1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Fix DDC-807, DDC-553

This commit is contained in:
Fabio B. Silva 2012-02-13 23:22:49 -02:00
parent 38d725ce32
commit 5d01123413
10 changed files with 123 additions and 12 deletions

View File

@ -203,9 +203,10 @@
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<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="length" type="xs:NMTOKEN" />
<xs:attribute name="column-definition" type="xs:string" />
<xs:anyAttribute namespace="##other"/>
</xs:complexType>
@ -278,6 +279,7 @@
<xs:attribute name="type" type="xs:NMTOKEN" />
<xs:attribute name="column" type="xs:NMTOKEN" />
<xs:attribute name="association-key" type="xs:boolean" default="false" />
<xs:attribute name="column-definition" type="xs:string" />
<xs:anyAttribute namespace="##other"/>
</xs:complexType>

View File

@ -33,4 +33,6 @@ final class DiscriminatorColumn implements Annotation
public $length;
/** @var mixed */
public $fieldName; // field name used in non-object hydration (array/scalar)
/** @var string */
public $columnDefinition;
}

View File

@ -228,7 +228,8 @@ class AnnotationDriver implements Driver
$metadata->setDiscriminatorColumn(array(
'name' => $discrColumnAnnot->name,
'type' => $discrColumnAnnot->type,
'length' => $discrColumnAnnot->length
'length' => $discrColumnAnnot->length,
'columnDefinition' => $discrColumnAnnot->columnDefinition
));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));

View File

@ -99,9 +99,10 @@ class XmlDriver extends AbstractFileDriver
if (isset($xmlRoot->{'discriminator-column'})) {
$discrColumn = $xmlRoot->{'discriminator-column'};
$metadata->setDiscriminatorColumn(array(
'name' => (string)$discrColumn['name'],
'type' => (string)$discrColumn['type'],
'length' => (string)$discrColumn['length']
'name' => isset($discrColumn['name']) ? (string)$discrColumn['name'] : null,
'type' => isset($discrColumn['type']) ? (string)$discrColumn['type'] : null,
'length' => isset($discrColumn['length']) ? (string)$discrColumn['length'] : null,
'columnDefinition' => isset($discrColumn['column-definition']) ? (string)$discrColumn['column-definition'] : null
));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));

View File

@ -96,9 +96,10 @@ class YamlDriver extends AbstractFileDriver
if (isset($element['discriminatorColumn'])) {
$discrColumn = $element['discriminatorColumn'];
$metadata->setDiscriminatorColumn(array(
'name' => $discrColumn['name'],
'type' => $discrColumn['type'],
'length' => $discrColumn['length']
'name' => isset($discrColumn['name']) ? (string)$discrColumn['name'] : null,
'type' => isset($discrColumn['type']) ? (string)$discrColumn['type'] : null,
'length' => isset($discrColumn['length']) ? (string)$discrColumn['length'] : null,
'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string)$discrColumn['columnDefinition'] : null
));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));

View File

@ -288,11 +288,16 @@ class SchemaTool
$discrColumn['length'] = 255;
}
$table->addColumn(
$discrColumn['name'],
$discrColumn['type'],
array('length' => $discrColumn['length'], 'notnull' => true)
$options = array(
'length' => isset($discrColumn['length']) ? $discrColumn['length'] : null,
'notnull' => true
);
if (isset($discrColumn['columnDefinition'])) {
$options['columnDefinition'] = $discrColumn['columnDefinition'];
}
$table->addColumn($discrColumn['name'], $discrColumn['type'], $options);
}
/**

View File

@ -434,6 +434,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('NAME', $class->columnNames['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 Phonenumber {}
class Group {}

View File

@ -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);

View File

@ -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>

View File

@ -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