1
0
mirror of synced 2024-12-05 03:06:05 +03:00

[DDC-2136] Fix exporting to YAML and XML with assocation keys.

This commit is contained in:
Benjamin Eberlei 2013-05-01 23:10:13 +02:00
parent d33e0a3488
commit 6d02c7e1a5
6 changed files with 25 additions and 7 deletions

View File

@ -19,6 +19,6 @@ before_script:
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database doctrine_tests;' -U postgres; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database doctrine_tests_tmp;' -U postgres; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS doctrine_tests_tmp;create database IF NOT EXISTS doctrine_tests;'; fi"
- composer install --prefer-source
- composer install --prefer-source --dev
script: phpunit --configuration tests/travis/$DB.travis.xml
script: phpunit --configuration tests/travis/$DB.travis.xml

View File

@ -19,6 +19,9 @@
"doctrine/dbal": ">=2.4-beta,<2.5-dev",
"symfony/console": "2.*"
},
"require-dev": {
"symfony/yaml": "2.1"
},
"suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
},

View File

@ -307,6 +307,7 @@ class YamlDriver extends FileDriver
}
}
// Evaluate oneToOne relationships
if (isset($element['oneToOne'])) {
foreach ($element['oneToOne'] as $name => $oneToOneElement) {

View File

@ -129,6 +129,15 @@ class XmlExporter extends AbstractExporter
}
}
foreach ($metadata->associationMappings as $name => $assoc) {
if (isset($assoc['id']) && $assoc['id']) {
$id[$name] = array(
'fieldName' => $name,
'associationKey' => true
);
}
}
if ( ! $metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
$id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
}
@ -137,7 +146,10 @@ class XmlExporter extends AbstractExporter
foreach ($id as $field) {
$idXml = $root->addChild('id');
$idXml->addAttribute('name', $field['fieldName']);
$idXml->addAttribute('type', $field['type']);
if (isset($field['type'])) {
$idXml->addAttribute('type', $field['type']);
}
if (isset($field['columnName'])) {
$idXml->addAttribute('column', $field['columnName']);

View File

@ -110,9 +110,7 @@ class YamlExporter extends AbstractExporter
$ids[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
}
if ($ids) {
$array['fields'] = $ids;
}
$array['id'] = $ids;
if ($fieldMappings) {
if ( ! isset($array['fields'])) {
@ -152,6 +150,10 @@ class YamlExporter extends AbstractExporter
'cascade' => $cascade,
);
if (isset($mapping['id']) && $mapping['id'] === true) {
$array['id'][$name]['associationKey'] = true;
}
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
$joinColumns = $associationMapping['joinColumns'];
$newJoinColumns = array();

View File

@ -178,7 +178,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
*/
public function testIdentifierIsExported($class)
{
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY, $class->generatorType);
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY, $class->generatorType, "Generator Type wrong");
$this->assertEquals(array('id'), $class->identifier);
$this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);