Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix DDC-807, DDC-553

  • Loading branch information...
commit 5d01123413c9eea68469af1eca37f7ae816ed1cc 1 parent 38d725c
@FabioBatSilva FabioBatSilva authored
View
4 doctrine-mapping.xsd
@@ -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
2  lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php
@@ -33,4 +33,6 @@
public $length;
/** @var mixed */
public $fieldName; // field name used in non-object hydration (array/scalar)
+ /** @var string */
+ public $columnDefinition;
}
View
3  lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
@@ -228,7 +228,8 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
$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
7 lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
@@ -99,9 +99,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
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
7 lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
@@ -96,9 +96,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
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
13 lib/Doctrine/ORM/Tools/SchemaTool.php
@@ -288,11 +288,16 @@ private function addDiscriminatorColumnDefinition($class, $table)
$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
51 tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
@@ -434,6 +434,21 @@ public function testNamingStrategy()
$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 @@ public static function loadMetadata(ClassMetadataInfo $metadata)
}
+/**
+ * @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
15 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC807Entity.php
@@ -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
20 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml
@@ -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
13 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.yml
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.