Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix/hack for target-document #286

Merged
merged 2 commits into from

1 participant

@dbu
Collaborator

is this enough to fix http://www.doctrine-project.org/jira/browse/PHPCR-110 ? in the ticket i am worried about returning null but i saw no problem arising when i do what i do here.

@dbu
Collaborator

i think this leads to the same situation as when the annotation is not specified, so it should be correct. i will check if we need the same for yml driver and then merge.

@dbu dbu merged commit 6ee1b95 into master
@dbu dbu deleted the target-document-optional branch
@dbu
Collaborator

not 100% if yml mapping is all correct or if we miss some functional tests with yml mapping. but at the very least it will be less wrong now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 24, 2013
  1. @dbu

    fix/hack for target-document

    dbu authored
Commits on May 26, 2013
  1. @dbu

    make yml work too

    dbu authored
This page is out of date. Refresh to see the latest.
View
4 doctrine-phpcr-odm-mapping.xsd
@@ -308,7 +308,7 @@
<xs:complexType name="reference-many">
<xs:complexContent>
<xs:extension base="phpcr:relation-type">
- <xs:attribute name="target-document" type="xs:string" use="required" />
+ <xs:attribute name="target-document" type="xs:string" use="optional" />
<xs:attribute name="strategy" type="phpcr:reference-strategy" use="optional" />
</xs:extension>
</xs:complexContent>
@@ -317,7 +317,7 @@
<xs:complexType name="reference-one">
<xs:complexContent>
<xs:extension base="phpcr:relation-type">
- <xs:attribute name="target-document" type="xs:string" use="required" />
+ <xs:attribute name="target-document" type="xs:string" use="optional" />
<xs:attribute name="strategy" type="phpcr:reference-strategy" use="optional" />
</xs:extension>
</xs:complexContent>
View
6 lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
@@ -21,6 +21,7 @@
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
+use Doctrine\Common\Util\Debug;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use Doctrine\Common\Persistence\Mapping\MappingException as DoctrineMappingException;
use SimpleXmlElement;
@@ -108,6 +109,9 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$mapping[$key] = ('true' === $mapping[$key]) ? true : false;
}
}
+ if (!isset($mapping['name'])) {
+ throw new MappingException(sprintf('Missing name attribute for field of %s', $className));
+ }
$mapping['fieldName'] = $mapping['name'];
unset($mapping['name']);
$class->mapField($mapping);
@@ -235,7 +239,7 @@ private function addReferenceMapping(ClassMetadata $class, $reference, $type)
$attributes = (array) $reference->attributes();
$mapping = $attributes["@attributes"];
$mapping['strategy'] = isset($mapping['strategy']) ? strtolower($mapping['strategy']) : null;
- $mapping['targetDocument'] = $mapping['target-document'];
+ $mapping['targetDocument'] = isset($mapping['target-document']) ? $mapping['target-document'] : null;
unset($mapping['target-document']);
if ($type === 'many') {
View
12 lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
@@ -176,15 +176,11 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] as $fieldName => $reference) {
- $reference['cascade'] = (isset($reference['cascade'])) ? $this->getCascadeMode($reference['cascade']) : 0;
- $reference['name'] = (isset($reference['name'])) ? $reference['name'] : null;
$this->addMappingFromReference($class, $fieldName, $reference, 'one');
}
}
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] as $fieldName => $reference) {
- $reference['cascade'] = (isset($reference['cascade'])) ? $this->getCascadeMode($reference['cascade']) : 0;
- $reference['name'] = (isset($reference['name'])) ? $reference['name'] : null;
$this->addMappingFromReference($class, $fieldName, $reference, 'many');
}
}
@@ -240,8 +236,16 @@ public function loadMetadataForClass($className, ClassMetadata $class)
private function addMappingFromReference(ClassMetadata $class, $fieldName, $reference, $type)
{
+ /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$mapping = array_merge(array('fieldName' => $fieldName), $reference);
+ $mapping['cascade'] = (isset($reference['cascade'])) ? $this->getCascadeMode($reference['cascade']) : 0;
+ $mapping['name'] = (isset($reference['name'])) ? $reference['name'] : null;
+
+ if (! isset($mapping['targetDocument'])) {
+ $mapping['targetDocument'] = null;
+ }
+
if ($type === 'many') {
$class->mapManyToMany($mapping);
} elseif ($type === 'one') {
Something went wrong with that request. Please try again.