From 33c68df3bab8c39b0f04e20a02d46891033593dc Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 5 Dec 2011 17:35:49 -0200 Subject: [PATCH] Fixed DDC-1170 --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 4 + .../ORM/Mapping/Driver/YamlDriver.php | 4 + .../ORM/Mapping/AbstractMappingDriverTest.php | 80 +++++++++++++++++++ ...ctrine.Tests.ORM.Mapping.DDC1170Entity.php | 16 ++++ ...ne.Tests.ORM.Mapping.DDC1170Entity.dcm.xml | 15 ++++ ...ne.Tests.ORM.Mapping.DDC1170Entity.dcm.yml | 10 +++ 6 files changed, 129 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6f655d0db..8228ba1ca 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -232,6 +232,10 @@ class XmlDriver extends AbstractFileDriver if (isset($idElement['column'])) { $mapping['columnName'] = (string)$idElement['column']; } + + if (isset($idElement['column-definition'])) { + $mapping['columnDefinition'] = (string)$idElement['column-definition']; + } $metadata->mapField($mapping); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a33c19b6b..4ef66f9f8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -181,6 +181,10 @@ class YamlDriver extends AbstractFileDriver if (isset($idElement['length'])) { $mapping['length'] = $idElement['length']; } + + if (isset($idElement['columnDefinition'])) { + $mapping['columnDefinition'] = $idElement['columnDefinition']; + } $metadata->mapField($mapping); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7c2887301..2499d4eb6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -373,6 +373,25 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType); } + + /** + * @group DDC-1170 + */ + public function testIdentifierColumnDefinition() + { + + $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity'); + + + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('value', $class->fieldMappings); + + $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']); + $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']); + + $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']); + $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']); + } } /** @@ -597,4 +616,65 @@ class Dog extends Animal { } +} + + +/** + * @Entity + */ +class DDC1170Entity +{ + + /** + * @param string $value + */ + function __construct($value = null) + { + $this->value = $value; + } + + /** + * @Id + * @GeneratedValue(strategy="NONE") + * @Column(type="integer", columnDefinition = "INT unsigned NOT NULL") + **/ + private $id; + + /** + * @Column(columnDefinition = "VARCHAR(255) NOT NULL") + */ + private $value; + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + public static function loadMetadata(ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnDefinition' => 'INT unsigned NOT NULL', + )); + + $metadata->mapField(array( + 'fieldName' => 'value', + 'columnDefinition' => 'VARCHAR(255) NOT NULL' + )); + + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); + } + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php new file mode 100644 index 000000000..97f4624ba --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php @@ -0,0 +1,16 @@ +mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnDefinition' => 'INT unsigned NOT NULL', +)); + +$metadata->mapField(array( + 'fieldName' => 'value', + 'columnDefinition' => 'VARCHAR(255) NOT NULL' +)); + +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml new file mode 100644 index 000000000..9f5ad7fac --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml new file mode 100644 index 000000000..8b2ac518b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml @@ -0,0 +1,10 @@ +Doctrine\Tests\ORM\Mapping\DDC1170Entity: + type: entity + id: + id: + columnDefinition: INT unsigned NOT NULL + generator: + strategy: NONE + fields: + value: + columnDefinition: VARCHAR(255) NOT NULL \ No newline at end of file