Browse files

Mapping exception when child doc. tries to change referenceable to false

  • Loading branch information...
1 parent 52eca52 commit 77845a6abd0a59a50a62b2e35e2871d0b2e85803 dantleech committed Oct 29, 2012
View
3 composer.json
@@ -15,7 +15,8 @@
"php": ">=5.3.2",
"doctrine/common": ">=2.3-dev,<2.4-dev",
"phpcr/phpcr-implementation": ">=2.1.0-beta3,<2.2.0-dev",
- "phpcr/phpcr-utils": ">=1.0-beta3"
+ "phpcr/phpcr-utils": ">=1.0-beta3",
+ "jackalope/jackalope-doctrine-dbal": "dev-master"
},
"require-dev": {
"symfony/yaml": ">=2.0.0,<2.3.0-dev"
View
5 lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -201,6 +201,11 @@ private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $pare
if ($parentClass->lifecycleCallbacks) {
$subClass->mapLifecycleCallbacks($parentClass->lifecycleCallbacks);
}
+
+ if ($parentClass->referenceable === true && $subClass->referenceable === false) {
+ throw MappingException::cannotOverrideReferenceableAsFalse($subClass->name);
+ }
+ $subClass->setReferenceable($parentClass->referenceable);
}
private function registerParentOnField(ClassMetadata $subClass, ClassMetadata $parentClass, $fieldName)
View
BIN tests/Doctrine/Tests/Models/Inheritance/.NonReferenceableChildDocument.php.swp
Binary file not shown.
View
BIN tests/Doctrine/Tests/Models/Inheritance/.ParentDocument.php.swp
Binary file not shown.
View
BIN tests/Doctrine/Tests/Models/Inheritance/.ReferenceableParentDocument.php.swp
Binary file not shown.
View
14 tests/Doctrine/Tests/Models/Inheritance/NonReferenceableChildDocument.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Doctrine\Tests\Models\Inheritance;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * @PHPCRODM\Document(referenceable=false)
+ */
+class NonReferenceableChildDocument extends ReferenceableParentDocument
+{
+}
+
+
View
22 tests/Doctrine/Tests/Models/Inheritance/ReferenceableParentDocument.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Documents;
+
+namespace Doctrine\Tests\Models\Inheritance;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * @PHPCRODM\Document(referenceable=true)
+ */
+class ReferenceableParentDocument
+{
+ /** @PHPCRODM\Id(strategy="repository") */
+ public $id;
+
+ public function getId()
+ {
+ return $this->id;
+ }
+}
+
View
18 tests/Doctrine/Tests/ODM/PHPCR/Mapping/ClassMetadataFactoryTest.php
@@ -56,4 +56,22 @@ public function testCacheDriver()
{
$this->markTestIncomplete('Test cache driver setting and handling.');
}
+MappingException
+ /**
+ * @expectedException
+ public function testAddInheritedFields()
+ {
+ $parentClass = 'Doctrine\Tests\Models\Inheritance\NonReferenceableChildDocument';
+ $childClass = 'Doctrine\Tests\Models\Inheritance\NonReferenceableChildDocument';
+
+ $driver = new \Doctrine\Common\Persistence\Mapping\Driver\PHPDriver(array(__DIR__ . '/Model/php'));
+ $this->dm->getConfiguration()->setMetadataDriverImpl($driver);
+
+ $parent = new \Doctrine\ODM\PHPCR\Mapping\ClassMetadata($parentClass);
+ $child = new \Doctrine\ODM\PHPCR\Mapping\ClassMetadata($childClass);
+ $cmf = new ClassMetadataFactory($this->dm);
+ $cmf->setMetadataFor($parent->name, $parent);
+ $cmf->setMetadataFor($child->name, $child);
+ $meta = $cmf->loadMetadata($child->name);
+ }
}

0 comments on commit 77845a6

Please sign in to comment.