From 59d4e0c8e7744329cece96bd40ed4aa0e6773dd5 Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Sat, 8 May 2010 17:01:20 +0200 Subject: [PATCH] [DDC-481] Fixed. --- .../ORM/Mapping/ClassMetadataFactory.php | 4 ++-- .../ORM/Mapping/ClassMetadataInfo.php | 22 +++++++++++-------- .../ORM/Mapping/Driver/AnnotationDriver.php | 15 +++++-------- lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php | 2 -- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 9 +++++--- .../ORM/Mapping/Driver/YamlDriver.php | 22 +++++++++---------- .../ORM/Mapping/ClassMetadataFactoryTest.php | 3 +++ 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index fb3a09906..6429989cd 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -277,9 +277,9 @@ class ClassMetadataFactory } else { $this->_completeIdGeneratorMapping($class); } - + if ($parent && $parent->isInheritanceTypeSingleTable()) { - $class->setTableName($parent->getTableName()); + $class->setPrimaryTable($parent->table); } $class->setParentClasses($visited); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index b173e395d..8a016fd47 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -903,8 +903,8 @@ class ClassMetadataInfo /** * Sets the name of the primary table the class is mapped to. * - * @param string $tableName The table name. - * @deprecated + * @param string $tableName The table name. + * @deprecated Use {@link setPrimaryTable}. */ public function setTableName($tableName) { @@ -912,18 +912,22 @@ class ClassMetadataInfo } /** - * Sets the primary table definition. The provided array must have the + * Sets the primary table definition. The provided array supports the * following structure: * - * name => - * schema => - * catalog => + * name => (optional, defaults to class name) + * indexes => array of indexes (optional) + * uniqueConstraints => array of constraints (optional) * - * @param array $primaryTableDefinition + * @param array $table */ - public function setPrimaryTable(array $primaryTableDefinition) + public function setPrimaryTable(array $table) { - $this->table = $primaryTableDefinition; + if (isset($table['name']) && $table['name'][0] == '`') { + $table['name'] = trim($table['name'], '`'); + $table['quoted'] = true; + } + $this->table = $table; } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index e44af01cf..6a61772a7 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -1,7 +1,5 @@ - * @author Guilherme Blanco - * @author Jonathan H. Wage - * @author Roman Borschel + * @since 2.0 + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan H. Wage + * @author Roman Borschel */ class AnnotationDriver implements Driver { diff --git a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php index 99b8a145a..ff86597f6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PHPDriver.php @@ -1,7 +1,5 @@ attributes + $table = array(); if (isset($xmlRoot['table'])) { - $metadata->table['name'] = (string)$xmlRoot['table']; + $table['name'] = (string)$xmlRoot['table']; } - + $metadata->setPrimaryTable($table); + + /* not implemented specially anyway. use table = schema.table if (isset($xmlRoot['schema'])) { $metadata->table['schema'] = (string)$xmlRoot['schema']; - } + }*/ if (isset($xmlRoot['inheritance-type'])) { $inheritanceType = (string)$xmlRoot['inheritance-type']; diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 873f9b21f..05a3fe125 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -1,7 +1,5 @@ - * @author Guilherme Blanco - * @author Jonathan H. Wage - * @author Roman Borschel + * @since 2.0 + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan H. Wage + * @author Roman Borschel */ class YamlDriver extends AbstractFileDriver { @@ -61,13 +56,16 @@ class YamlDriver extends AbstractFileDriver } // Evaluate root level properties + $table = array(); if (isset($element['table'])) { - $metadata->table['name'] = $element['table']; + $table['name'] = $element['table']; } + $metadata->setPrimaryTable($table); + /* not implemented specially anyway. use table = schema.table if (isset($element['schema'])) { $metadata->table['schema'] = $element['schema']; - } + }*/ if (isset($element['inheritanceType'])) { $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType']))); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index fcce4dff8..5236bdf91 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -26,6 +26,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase // Self-made metadata $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1->setPrimaryTable(array('name' => '`group`')); // Add a mapped field $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); // Add a mapped field @@ -54,6 +55,8 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase // Go $cm1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $this->assertEquals('group', $cm1->table['name']); + $this->assertTrue($cm1->table['quoted']); $this->assertEquals(array(), $cm1->parentClasses); $this->assertTrue($cm1->hasField('name')); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType);