1
0
mirror of synced 2025-01-18 14:31:40 +03:00

[2.0][DDC-72] Fixes issue with converting D1 column aliases to D2 field names

This commit is contained in:
jwage 2009-11-11 21:15:27 +00:00
parent fa4046787e
commit fdd1954a7b
4 changed files with 22 additions and 8 deletions

View File

@ -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']])) {

View File

@ -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']) {

View File

@ -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);

View File

@ -9,6 +9,8 @@ User:
password:
type: string(255)
clob: clob
test_alias as theAlias:
type: string(255)
indexes:
username:
fields: [username]