Skip to content

Commit

Permalink
Mapping exception when child doc. tries to change referenceable to false
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Oct 29, 2012
1 parent 52eca52 commit 77845a6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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
{
}


Original file line number Diff line number Diff line change
@@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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.