From 2a005019bf9959e2d871d9866dbfce021d0c3a05 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 1 Jan 2011 21:47:04 +0100 Subject: [PATCH] DDC-117 - Add XML and YML Driver support for associated identifier. --- doctrine-mapping.xsd | 3 ++- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 14 ++++++++++++++ lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 2dde4d9b8..680123fd0 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -187,8 +187,9 @@ - + + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 91892e2b3..cd84849ae 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -194,7 +194,13 @@ class XmlDriver extends AbstractFileDriver } // Evaluate mappings + $associationIds = array(); foreach ($xmlRoot->id as $idElement) { + if ((bool)$idElement['association-key'] == true) { + $associationIds[(string)$idElement['fieldName']] = true; + continue; + } + $mapping = array( 'id' => true, 'fieldName' => (string)$idElement['name'], @@ -235,6 +241,10 @@ class XmlDriver extends AbstractFileDriver 'targetEntity' => (string)$oneToOneElement['target-entity'] ); + if (isset($associationIds[$mapping['fieldName']])) { + $mapping['id'] = true; + } + if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$oneToOneElement['fetch']); } @@ -311,6 +321,10 @@ class XmlDriver extends AbstractFileDriver 'targetEntity' => (string)$manyToOneElement['target-entity'] ); + if (isset($associationIds[$mapping['fieldName']])) { + $mapping['id'] = true; + } + if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$manyToOneElement['fetch']); } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index e714c50a0..0a6c6d0bd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -135,9 +135,15 @@ class YamlDriver extends AbstractFileDriver } } + $associationIds = array(); if (isset($element['id'])) { // Evaluate identifier settings foreach ($element['id'] as $name => $idElement) { + if (isset($idElement['associationKey']) && $idElement['associationKey'] == true) { + $associationIds[$name] = true; + continue; + } + if (!isset($idElement['type'])) { throw MappingException::propertyTypeIsRequired($className, $name); } @@ -234,6 +240,10 @@ class YamlDriver extends AbstractFileDriver 'targetEntity' => $oneToOneElement['targetEntity'] ); + if (isset($associationIds[$mapping['fieldName']])) { + $mapping['id'] = true; + } + if (isset($oneToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $oneToOneElement['fetch']); } @@ -303,6 +313,10 @@ class YamlDriver extends AbstractFileDriver 'targetEntity' => $manyToOneElement['targetEntity'] ); + if (isset($associationIds[$mapping['fieldName']])) { + $mapping['id'] = true; + } + if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $manyToOneElement['fetch']); }