diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index d4ab0499b..83bb5d8f8 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -150,13 +150,19 @@ class ConvertDoctrine1Schema $column = array(); $column['type'] = $string; } + if ( ! isset($column['name'])) { + $column['name'] = $name; + } + // check if a column alias was used (column_name as field_name) + if (preg_match("/(\w+)\sas\s(\w+)/i", $column['name'], $matches)) { + $name = $matches[1]; + $column['name'] = $name; + $column['alias'] = $matches[2]; + } if (preg_match("/([a-zA-Z]+)\(([0-9]+)\)/", $column['type'], $matches)) { $column['type'] = $matches[1]; $column['length'] = $matches[2]; } - if ( ! isset($column['name'])) { - $column['name'] = $name; - } $column['type'] = strtolower($column['type']); // check if legacy column type (1.x) needs to be mapped to a 2.0 one if (isset($this->_legacyTypeMap[$column['type']])) { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index cf07f8e2f..78b6eeffe 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -106,10 +106,14 @@ class YamlExporter extends AbstractExporter unset($fieldMapping['length']); } - unset($fieldMapping['fieldName']); - - if ($fieldMapping['columnName'] == $name) { - unset($fieldMapping['columnName']); + $fieldMapping['column'] = $fieldMapping['columnName']; + unset( + $fieldMapping['columnName'], + $fieldMapping['fieldName'] + ); + + if ($fieldMapping['column'] == $name) { + unset($fieldMapping['column']); } if (isset($fieldMapping['id']) && $fieldMapping['id']) { diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index efe97acb0..614d395f8 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -57,8 +57,10 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('Profile', $metadatas['Profile']->name); $this->assertEquals('User', $metadatas['User']->name); $this->assertEquals(4, count($metadatas['Profile']->fieldMappings)); - $this->assertEquals(4, count($metadatas['User']->fieldMappings)); + $this->assertEquals(5, count($metadatas['User']->fieldMappings)); $this->assertEquals('text', $metadatas['User']->fieldMappings['clob']['type']); + $this->assertEquals('test_alias', $metadatas['User']->fieldMappings['theAlias']['columnName']); + $this->assertEquals('theAlias', $metadatas['User']->fieldMappings['theAlias']['fieldName']); $this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName); $this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName); diff --git a/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml b/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml index 830ba2d69..67301c05d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml +++ b/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml @@ -9,6 +9,8 @@ User: password: type: string(255) clob: clob + test_alias as theAlias: + type: string(255) indexes: username: fields: [username]