[DDC-2136] Fix exporting to YAML and XML with assocation keys.
This commit is contained in:
parent
d33e0a3488
commit
6d02c7e1a5
@ -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
|
||||
|
@ -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"
|
||||
},
|
||||
|
@ -307,6 +307,7 @@ class YamlDriver extends FileDriver
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Evaluate oneToOne relationships
|
||||
if (isset($element['oneToOne'])) {
|
||||
foreach ($element['oneToOne'] as $name => $oneToOneElement) {
|
||||
|
@ -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']);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user