Permalink
Browse files

Merge pull request #185 from dantleech/inherit-referenceable

Make sub classes inherit the parents referenceable property
  • Loading branch information...
2 parents 52eca52 + c270f94 commit f5fb5ba3f080846826937c118985d094b49eab77 @dbu dbu committed Nov 1, 2012
@@ -201,6 +201,8 @@ private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $pare
if ($parentClass->lifecycleCallbacks) {
$subClass->mapLifecycleCallbacks($parentClass->lifecycleCallbacks);
}
+
+ $subClass->setReferenceable($parentClass->referenceable);
}
private function registerParentOnField(ClassMetadata $subClass, ClassMetadata $parentClass, $fieldName)
@@ -56,4 +56,36 @@ public function testCacheDriver()
{
$this->markTestIncomplete('Test cache driver setting and handling.');
}
+
+ public function testLoadMetadata_referenceableChildOverriddenAsFalse()
+ {
+ // if the child class overrides referenceable as false it is not taken into account
+ // as we only ever set the referenceable property to TRUE. This prevents us from
+ // knowing if the user has explicitly set referenceable to FALSE on a child entity.
+
+ $cache = new \Doctrine\Common\Cache\ArrayCache();
+ $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
+ $annotationDriver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader);
+ $annotationDriver->addPaths(array(__DIR__ . '/Model'));
+ $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver);
+
+ $cmf = new ClassMetadataFactory($this->dm);
+ $meta = $cmf->getMetadataFor('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceableChildReferenceableFalseMappingObject');
+
+ $this->assertTrue($meta->referenceable);
+ }
+
+ public function testLoadMetadata_referenceableChild()
+ {
+ $cache = new \Doctrine\Common\Cache\ArrayCache();
+ $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
+ $annotationDriver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader);
+ $annotationDriver->addPaths(array(__DIR__ . '/Model'));
+ $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver);
+
+ $cmf = new ClassMetadataFactory($this->dm);
+ $meta = $cmf->getMetadataFor('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceableChildMappingObject');
+
+ $this->assertTrue($meta->referenceable);
+ }
}
@@ -0,0 +1,18 @@
+<?php
+
+namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * Object which extends a referenceable object and so should also
+ * be referenceable.
+ *
+ * @PHPCRODM\Document()
+ */
+class ReferenceableChildMappingObject extends ReferenceableMappingObject
+{
+ /** @PHPCRODM\Id */
+ public $id;
+}
+
@@ -0,0 +1,18 @@
+<?php
+
+namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * An object that extends a referenceable object but sets
+ * referenceable to FALSE, which is not permitted.
+ *
+ * @PHPCRODM\Document(referenceable=false)
+ */
+class ReferenceableChildReferenceableFalseMappingObject extends ReferenceableMappingObject
+{
+ /** @PHPCRODM\Id */
+ public $id;
+}
+

0 comments on commit f5fb5ba

Please sign in to comment.