From a652bc69b3d509ffd2e44fe5afa3c5fe11e0982b Mon Sep 17 00:00:00 2001 From: beberlei Date: Wed, 27 Jan 2010 23:00:55 +0000 Subject: [PATCH] [2.0] DDC-247 - Fix bug with nullable not working in XML field and join-column properties. --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 +++++++--- tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php | 8 +++++++- .../xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml | 4 ++-- .../yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml | 4 ++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index d1dd4e7cb..be4ba8d77 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -148,12 +148,16 @@ class XmlDriver extends AbstractFileDriver } if (isset($fieldMapping['unique'])) { - $mapping['unique'] = (bool)$fieldMapping['unique']; + $mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true; } if (isset($fieldMapping['options'])) { $mapping['options'] = (array)$fieldMapping['options']; } + + if (isset($fieldMapping['nullable'])) { + $mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true; + } if (isset($fieldMapping['version']) && $fieldMapping['version']) { $metadata->setVersionMapping($mapping); @@ -407,11 +411,11 @@ class XmlDriver extends AbstractFileDriver ); if (isset($joinColumnElement['unique'])) { - $joinColumn['unique'] = (bool)$joinColumnElement['unique']; + $joinColumn['unique'] = ((string)$joinColumnElement['unique'] == "false") ? false : true; } if (isset($joinColumnElement['nullable'])) { - $joinColumn['nullable'] = (bool)$joinColumnElement['nullable']; + $joinColumn['nullable'] = ((string)$joinColumnElement['nullable'] == "false") ? false : true; } if (isset($joinColumnElement['onDelete'])) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php index cce7c6dbf..b2c9ae9cb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php @@ -50,7 +50,7 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(1, count($classNames)); } - private function _testUserClassMapping($class) + private function _testUserClassMapping(ClassMetadata $class) { $this->assertEquals('cms_users', $class->getTableName()); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->getInheritanceType()); @@ -58,6 +58,8 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['name'])); $this->assertEquals('string', $class->fieldMappings['name']['type']); + $this->assertTrue($class->fieldMappings['name']['nullable']); + $this->assertTrue($class->fieldMappings['name']['unique']); $this->assertEquals(array('id'), $class->identifier); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->getIdGeneratorType()); @@ -92,6 +94,10 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($class->associationMappings['groups']->isCascadeRefresh); $this->assertTrue($class->associationMappings['groups']->isCascadeDetach); $this->assertTrue($class->associationMappings['groups']->isCascadeMerge); + + // Non-Nullability of Join Column + $this->assertFalse($class->associationMappings['groups']->joinTable['joinColumns'][0]['nullable']); + $this->assertFalse($class->associationMappings['groups']->joinTable['joinColumns'][0]['unique']); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 932b8cc3b..5d6c68c74 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -16,7 +16,7 @@ - + @@ -34,7 +34,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index c29e6c908..501a0d3b0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -10,6 +10,8 @@ Doctrine\Tests\ORM\Mapping\User: name: type: string length: 50 + nullable: true + unique: true oneToOne: address: targetEntity: Address @@ -30,6 +32,8 @@ Doctrine\Tests\ORM\Mapping\User: joinColumns: user_id: referencedColumnName: id + nullable: false + unique: false inverseJoinColumns: group_id: referencedColumnName: id