From 86054eb659a8589ec23f50be55b30837688a1112 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sun, 12 Feb 2012 22:24:03 -0200 Subject: [PATCH] fix DDC-1642 --- .../ORM/Persisters/BasicEntityPersister.php | 5 ++- .../Models/CustomType/CustomTypeUpperCase.php | 5 +++ .../Tests/ORM/Functional/TypeValueSqlTest.php | 37 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index d2f1b4661..629c1fa2a 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1152,9 +1152,10 @@ class BasicEntityPersister foreach ($columns AS $column) { $placeholder = '?'; - if (isset($this->_columnTypes[$column]) && + if (isset($this->_class->fieldNames[$column]) && + isset($this->_columnTypes[$this->_class->fieldNames[$column]]) && isset($this->_class->fieldMappings[$this->_class->fieldNames[$column]]['requireSQLConversion'])) { - $type = Type::getType($this->_columnTypes[$column]); + $type = Type::getType($this->_columnTypes[$this->_class->fieldNames[$column]]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->_platform); } diff --git a/tests/Doctrine/Tests/Models/CustomType/CustomTypeUpperCase.php b/tests/Doctrine/Tests/Models/CustomType/CustomTypeUpperCase.php index 26e0ec115..e4b46e880 100644 --- a/tests/Doctrine/Tests/Models/CustomType/CustomTypeUpperCase.php +++ b/tests/Doctrine/Tests/Models/CustomType/CustomTypeUpperCase.php @@ -18,4 +18,9 @@ class CustomTypeUpperCase * @Column(type="upper_case_string") */ public $lowerCaseString; + + /** + * @Column(type="upper_case_string", name="named_lower_case_string", nullable = true) + */ + public $namedLowerCaseString; } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index 1bd5184d0..537f238ca 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -47,6 +47,43 @@ class TypeValueSqlTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('FOO', $this->_em->getConnection()->fetchColumn("select lowerCaseString from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); } + /** + * @group DDC-1642 + */ + public function testUpperCaseStringTypeWhenColumnNameIsDefined() + { + + $entity = new CustomTypeUpperCase(); + $entity->lowerCaseString = 'Some Value'; + $entity->namedLowerCaseString = 'foo'; + + $this->_em->persist($entity); + $this->_em->flush(); + + $id = $entity->id; + + $this->_em->clear(); + + $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); + $this->assertEquals('foo', $entity->namedLowerCaseString, 'Entity holds lowercase string'); + $this->assertEquals('FOO', $this->_em->getConnection()->fetchColumn("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); + + + $entity->namedLowerCaseString = 'bar'; + + $this->_em->persist($entity); + $this->_em->flush(); + + $id = $entity->id; + + $this->_em->clear(); + + + $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); + $this->assertEquals('bar', $entity->namedLowerCaseString, 'Entity holds lowercase string'); + $this->assertEquals('BAR', $this->_em->getConnection()->fetchColumn("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); + } + public function testTypeValueSqlWithAssociations() { $parent = new CustomTypeParent();