1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +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;' -U postgres; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database doctrine_tests_tmp;' -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" - 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", "doctrine/dbal": ">=2.4-beta,<2.5-dev",
"symfony/console": "2.*" "symfony/console": "2.*"
}, },
"require-dev": {
"symfony/yaml": "2.1"
},
"suggest": { "suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver" "symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
}, },

View file

@ -307,6 +307,7 @@ class YamlDriver extends FileDriver
} }
} }
// Evaluate oneToOne relationships // Evaluate oneToOne relationships
if (isset($element['oneToOne'])) { if (isset($element['oneToOne'])) {
foreach ($element['oneToOne'] as $name => $oneToOneElement) { 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)) { if ( ! $metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
$id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
} }
@ -137,7 +146,10 @@ class XmlExporter extends AbstractExporter
foreach ($id as $field) { foreach ($id as $field) {
$idXml = $root->addChild('id'); $idXml = $root->addChild('id');
$idXml->addAttribute('name', $field['fieldName']); $idXml->addAttribute('name', $field['fieldName']);
$idXml->addAttribute('type', $field['type']);
if (isset($field['type'])) {
$idXml->addAttribute('type', $field['type']);
}
if (isset($field['columnName'])) { if (isset($field['columnName'])) {
$idXml->addAttribute('column', $field['columnName']); $idXml->addAttribute('column', $field['columnName']);

View file

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

View file

@ -178,7 +178,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
*/ */
public function testIdentifierIsExported($class) 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->assertEquals(array('id'), $class->identifier);
$this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true); $this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);