From 5fb699f3934e760f273a67fa46e195ab1b264d19 Mon Sep 17 00:00:00 2001 From: Johannes Stark Date: Thu, 18 Aug 2011 17:06:36 +0200 Subject: [PATCH] added support for hard and weak referrers --- lib/Doctrine/ODM/PHPCR/DocumentManager.php | 4 +- .../Annotations/DoctrineAnnotations.php | 1 + .../ODM/PHPCR/Mapping/ClassMetadataInfo.php | 11 +- .../ODM/PHPCR/Proxy/ReferenceProxyFactory.php | 15 + .../ODM/PHPCR/ReferrersCollection.php | 5 +- lib/Doctrine/ODM/PHPCR/UnitOfWork.php | 34 +- .../Tests/ODM/PHPCR/Functional/ChildTest.php | 58 +++- .../ODM/PHPCR/Functional/ChildrenTest.php | 58 ++++ .../ODM/PHPCR/Functional/ReferrerTest.php | 322 +++++++++++++++--- 9 files changed, 451 insertions(+), 57 deletions(-) diff --git a/lib/Doctrine/ODM/PHPCR/DocumentManager.php b/lib/Doctrine/ODM/PHPCR/DocumentManager.php index 4defc2c80..3894203d8 100644 --- a/lib/Doctrine/ODM/PHPCR/DocumentManager.php +++ b/lib/Doctrine/ODM/PHPCR/DocumentManager.php @@ -326,9 +326,9 @@ public function getChildren($document, $filter = null) * @param string|array $name optional name to match on referrers names * @return a collection of referrer documents */ - public function getReferrers($document, $name = null) + public function getReferrers($document, $type = "all", $name = null) { - return $this->unitOfWork->getReferrers($document, $name); + return $this->unitOfWork->getReferrers($document, $type, $name); } /** diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php index df1bf0b22..19b6c8ec2 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php @@ -95,6 +95,7 @@ class Children extends Annotation class Referrers extends Annotation { public $filterName = null; + public $referenceType = "all"; } final class EmbeddedDocument extends Annotation {} diff --git a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php index 13a199467..d35ec2593 100644 --- a/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataInfo.php @@ -527,11 +527,20 @@ public function mapChildren(array $mapping) public function mapReferrers(array $mapping) { - $mapping = $this->validateAndCompleteFieldMapping($mapping, false); + $mapping = $this->validateAndCompleteReferrersMapping($mapping, false); $mapping['name'] = $mapping['fieldName']; $this->referrersMappings[$mapping['fieldName']] = $mapping; } + protected function validateAndCompleteReferrersMapping($mapping) + { + $mapping = $this->validateAndCompleteFieldMapping($mapping, false); + if (!isset($mapping['referenceType']) && in_array($mapping['referenceType'], array("all", "weak", "hard"))) { + throw new MappingException("You have to specify a 'referenceType' for the '" . $this->name . "' association which must be 'all', 'weak' or 'hard'."); + } + return $mapping; + } + protected function validateAndCompleteFieldMapping($mapping, $isField = true) { if (!isset($mapping['fieldName'])) { diff --git a/lib/Doctrine/ODM/PHPCR/Proxy/ReferenceProxyFactory.php b/lib/Doctrine/ODM/PHPCR/Proxy/ReferenceProxyFactory.php index 28ba14920..dc811955d 100644 --- a/lib/Doctrine/ODM/PHPCR/Proxy/ReferenceProxyFactory.php +++ b/lib/Doctrine/ODM/PHPCR/Proxy/ReferenceProxyFactory.php @@ -174,6 +174,21 @@ private function getUnsetAttributes(ClassMetadata $class) $attributes .= ", "; } + foreach ($class->referrersMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childrenMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + + foreach ($class->childMappings as $field) { + $attributes .= '$this->'.$field["fieldName"]; + $attributes .= ", "; + } + $attributes = substr($attributes, 0, -2); return "unset(".$attributes.");"; diff --git a/lib/Doctrine/ODM/PHPCR/ReferrersCollection.php b/lib/Doctrine/ODM/PHPCR/ReferrersCollection.php index 111d9ed59..6b5fbaed7 100644 --- a/lib/Doctrine/ODM/PHPCR/ReferrersCollection.php +++ b/lib/Doctrine/ODM/PHPCR/ReferrersCollection.php @@ -15,17 +15,18 @@ class ReferrersCollection extends PersistentCollection private $dm; private $name; - public function __construct($document, DocumentManager $dm, $name= null) + public function __construct($document, DocumentManager $dm, $type = "all", $name = null) { $this->document = $document; $this->dm = $dm; + $this->type = $type; $this->name = $name; } protected function load() { if (null === $this->col) { - $this->col = $this->dm->getReferrers($this->document, $this->name); + $this->col = $this->dm->getReferrers($this->document, $this->type, $this->name); } } } diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index daa2bdf07..59d8bb731 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -238,8 +238,10 @@ public function createDocument($documentName, $node, array &$hints = array()) } } - $session = $this->dm->getPhpcrSession(); - $refNodes = $session->getNodesByIdentifier($refNodeUUIDs); + if (count($refNodeUUIDs) > 0) { + $session = $this->dm->getPhpcrSession(); + $refNodes = $session->getNodesByIdentifier($refNodeUUIDs); + } // initialize inverse side collections foreach ($class->associationsMappings as $assocName => $assocOptions) { @@ -340,7 +342,7 @@ public function createDocument($documentName, $node, array &$hints = array()) } foreach ($class->referrersMappings as $mapping) { - $documentState[$mapping['fieldName']] = new ReferrersCollection($document, $this->dm, $mapping['filterName']); + $documentState[$mapping['fieldName']] = new ReferrersCollection($document, $this->dm, $mapping['referenceType'], $mapping['filterName']); } if (isset($documentName) && $this->validateDocumentName && !($document instanceof $documentName)) { @@ -1159,16 +1161,34 @@ public function getChildren($document, $filter = null) * @param string|array $name optional name to match on referrers names * @return a collection of referrer documents */ - public function getReferrers($document, $name = null) + public function getReferrers($document, $type = "all", $name = null) { $oid = spl_object_hash($document); $node = $this->nodesMap[$oid]; - $referrerProperties = $node->getReferences($name); + $referrerDocuments = array(); - foreach ($referrerProperties as $name => $referrerProperty) { + $referrerPropertiesW = array(); + $referrerPropertiesH = array(); + + if ($type === "all") { + $referrerPropertiesW = $node->getWeakReferences($name); + $referrerPropertiesH = $node->getReferences($name); + } elseif ($type === "weak") { + $referrerPropertiesW = $node->getWeakReferences($name); + } elseif ($type === "hard") { + $referrerPropertiesH = $node->getReferences($name); + } + + foreach ($referrerPropertiesW as $referrerProperty) { $referrerNode = $referrerProperty->getParent(); - $referrerDocuments[$name] = $this->createDocument(null, $referrerNode); + $referrerDocuments[] = $this->createDocument(null, $referrerNode); } + + foreach ($referrerPropertiesH as $referrerProperty) { + $referrerNode = $referrerProperty->getParent(); + $referrerDocuments[] = $this->createDocument(null, $referrerNode); + } + return new ArrayCollection($referrerDocuments); } diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildTest.php index b36932b84..554ed9c64 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildTest.php @@ -236,8 +236,33 @@ public function testModificationAfterPersist() $this->assertNotNull($parent->child); $this->assertEquals('Changed', $parent->child->name); } -} + public function testChildOfReference() + { + $referrerTestObj = new ChildReferrerTestObj(); + $referrerTestObj->id = "/functional/referrerTestObj"; + $referrerTestObj->name = "referrerTestObj"; + + $refererenceableTestObj = new ChildReferenceableTestObj(); + $refererenceableTestObj->id = "/functional/referenceableTestObj"; + $refererenceableTestObj->name = "referenceableTestObj"; + $referrerTestObj->reference = $refererenceableTestObj; + + $this->dm->persist($referrerTestObj); + + $ChildTestObj = new ChildTestObj(); + $ChildTestObj->id = "/functional/referenceableTestObj/test"; + $ChildTestObj->name= "childTestObj"; + + $this->dm->persist($ChildTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $referrer = $this->dm->find(null, "/functional/referrerTestObj"); + + $this->assertEquals($referrer->reference->aChild->name, "childTestObj"); + } +} /** * @PHPCRODM\Document(alias="childTestObj") @@ -251,6 +276,7 @@ class ChildChildTestObj /** @PHPCRODM\String */ public $name; } + /** * @PHPCRODM\Document(alias="testObj") */ @@ -265,3 +291,33 @@ class ChildTestObj /** @PHPCRODM\Child(name="test") */ public $child; } + +/** + * @PHPCRODM\Document(alias="ChildReferrerTestObj") + */ +class ChildReferrerTestObj +{ + /** @PHPCRODM\Id */ + public $id; + + /** @PHPCRODM\String */ + public $name; + + /** @PHPCRODM\ReferenceOne(targetDocument="ChildReferenceableTestObj") */ + public $reference; +} + +/** + * @PHPCRODM\Document(alias="ChildReferenceableTestObj", referenceable="true") + */ +class ChildReferenceableTestObj +{ + /** @PHPCRODM\Id */ + public $id; + + /** @PHPCRODM\String */ + public $name; + + /** @PHPCRODM\Child(name="test") */ + public $aChild; +} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildrenTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildrenTest.php index bd1e822f6..5473099a2 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildrenTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ChildrenTest.php @@ -76,6 +76,34 @@ public function testAnnotation() $this->assertEquals(1, count($parent->aChildren)); $this->assertEquals(4, count($parent->allChildren)); } + + public function testChildrenOfReference() + { + $referrerTestObj = new ChildrenReferrerTestObj(); + $referrerTestObj->id = "/functional/referrerTestObj"; + $referrerTestObj->name = "referrerTestObj"; + + $refererenceableTestObj = new ChildrenReferenceableTestObj(); + $refererenceableTestObj->id = "/functional/referenceableTestObj"; + $refererenceableTestObj->name = "referenceableTestObj"; + $referrerTestObj->reference = $refererenceableTestObj; + + $this->dm->persist($referrerTestObj); + + $ChildrenTestObj = new ChildrenTestObj(); + $ChildrenTestObj->id = "/functional/referenceableTestObj/childrenTestObj"; + $ChildrenTestObj->name= "childrenTestObj"; + + $this->dm->persist($ChildrenTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $referrer = $this->dm->find(null, "/functional/referrerTestObj"); + + $this->assertEquals(count($referrer->reference->allChildren), 1); + $this->assertEquals($referrer->reference->allChildren->first()->name, "childrenTestObj"); + + } } /** @@ -95,3 +123,33 @@ class ChildrenTestObj /** @PHPCRODM\Children */ public $allChildren; } + +/** + * @PHPCRODM\Document(alias="Referrer") + */ +class ChildrenReferrerTestObj +{ + /** @PHPCRODM\Id */ + public $id; + + /** @PHPCRODM\String */ + public $name; + + /** @PHPCRODM\ReferenceOne(targetDocument="ChildrenReferenceableTestObj") */ + public $reference; +} + +/** + * @PHPCRODM\Document(alias="ChildrenReferenceableTestObj", referenceable="true") + */ +class ChildrenReferenceableTestObj +{ + /** @PHPCRODM\Id */ + public $id; + + /** @PHPCRODM\String */ + public $name; + + /** @PHPCRODM\Children */ + public $allChildren; +} diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferrerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferrerTest.php index 7e870c26d..5e225b707 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferrerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferrerTest.php @@ -97,39 +97,6 @@ public function testCreateManyRef() } } - public function testCreateAddRefLater() - { - $referrerTestObj = new ReferrerTestObj(); - $referrerTestObj->name = "referrer"; - $referrerTestObj->id = "/functional/referrerTestObj"; - - $this->dm->persist($referrerTestObj); - - $referrerRefTestObj = new ReferrerRefTestObj(); - $referrerRefTestObj->id = "/functional/referrerRefTestObj"; - $referrerRefTestObj->name = "referenced"; - - $this->dm->persist($referrerRefTestObj); - - $this->dm->flush(); - $this->dm->clear(); - - $reference = $this->dm->find(null, "/functional/referrerRefTestObj"); - $this->assertEquals(count($reference->referrers), 0); - - $referrer = $this->dm->find(null, "/functional/referrerTestObj"); - - $referrer->reference = $reference; - - $this->dm->flush(); - $this->dm->clear(); - - $tmpReference = $this->dm->find(null, "/functional/referrerRefTestObj"); - - $this->assertEquals(count($tmpReference->referrers), 1); - $this->assertEquals($tmpReference->referrers->first()->id, "/functional/referrerTestObj"); - } - public function testUpdate() { $referrerTestObj = new ReferrerTestObj(); @@ -285,7 +252,7 @@ public function testRemoveReferrer() $this->assertFalse($reference->referrers->first()); } - public function testRemoveReferrerMany() + public function testRemoveReferrerOneInMany() { $max = 5; @@ -331,10 +298,8 @@ public function testRemoveReferrerMany() /** * Remove referenced node, but change referrer node before */ - public function testRemoveReferrerChangeBevore() { - $referrerTestObj = new ReferrerTestObj(); $referrerRefTestObj = new ReferrerRefTestObj(); @@ -349,21 +314,277 @@ public function testRemoveReferrerChangeBevore() $this->dm->flush(); $this->dm->clear(); + $reference = $this->dm->find(null, "/functional/referrerRefTestObj"); + $reference->referrers[0]->name = "referenced changed"; + + $referrer = $this->dm->find(null, "/functional/referrerTestObj"); + $referrer->reference = null; + + $this->dm->remove($reference); + $this->dm->flush(); + $this->dm->clear(); + + $reference = $this->dm->find(null, "/functional/referrerRefTestObj"); + $this->assertNull($reference); + + $referrer = $this->dm->find(null, "/functional/referrerTestObj"); + $this->assertEquals($referrer->name, "referenced changed"); + } + + /** + * Remove referenced node, but change referrer nodes before + */ + public function testRemoveReferrerManyChangeBevore() + { + $referrerRefManyTestObj = new ReferrerRefTestObj(); + $referrerRefManyTestObj->id = "/functional/referrerRefManyTestObj"; + + $max = 5; + for ($i = 0; $i < $max; $i++) { + $newReferrerTestObj = new ReferrerTestObj(); + $newReferrerTestObj->id = "/functional/referrerTestObj$i"; + $newReferrerTestObj->name = "referrerTestObj$i"; + $newReferrerTestObj->reference = $referrerRefManyTestObj; + $this->dm->persist($newReferrerTestObj); + } + + $this->dm->persist($referrerRefManyTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $reference = $this->dm->find(null, "/functional/referrerRefManyTestObj"); + $names = array(); + $i = 0; + foreach ($reference->referrers as $referrer) { + $name = "new name $i"; + $names[] = $name; + $referrer->name = $name; + $i++; + } + $this->assertEquals($i, $max); - $reference = $this->dm->find($this->referrerType, "/functional/referrerRefTestObj"); - $reference->referrers[0]->name = "referenced changed"); + for ($i = 0; $i < $max; $i++) { + $referrer = $this->dm->find(null, "/functional/referrerTestObj$i"); + $referrer->reference = null; + } $this->dm->remove($reference); $this->dm->flush(); $this->dm->clear(); - $reference = $this->dm->find($this->referrerType, '/functional/referrerRefTestObj'); - $this->assertNull($reference); + $refNames = array(); + for ($i = 0; $i < $max; $i++) { + $referrer = $this->dm->find(null, "/functional/referrerTestObj$i"); + $refNames[] = $referrer->name; + } + $this->assertEquals($i, $max); - $referrer = $this->dm->find($this->referrerType, '/functional/referrerTestObj'); - $this->assertEquals($referrer->name, 'referenced changed'); + foreach ($names as $name) { + $this->assertTrue(in_array($name, $refNames)); + } } + + public function testDeleteByRef() + { + $referrerTestObj = new ReferrerTestObj(); + $referrerRefTestObj = new ReferrerRefTestObj(); + + $referrerTestObj->id = "/functional/referrerTestObj"; + $referrerRefTestObj->id = "/functional/referrerRefTestObj"; + $referrerRefTestObj->name = "referenced"; + + $referrerTestObj->reference = $referrerRefTestObj; + + $this->dm->persist($referrerTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $reference = $this->dm->find(null, "/functional/referrerRefTestObj"); + + $this->dm->remove($reference->referrers[0]); + + $this->dm->flush(); + $this->dm->clear(); + + $this->assertEquals(count($this->dm->find(null, "/functional/referrerRefTestObj")->referrers), 0); + $this->assertFalse($this->session->getNode("/functional")->hasNode("referrerTestObj")); + } + + public function testWeakHardRef() + { + $weakReferrerTestObj = new WeakReferrerTestObj(); + $weakReferrerTestObj->id = "/functional/weakReferrerTestObj"; + $weakReferrerTestObj->name = "weakReferrerTestObj"; + + $hardReferrerTestObj = new HardReferrerTestObj(); + $hardReferrerTestObj->id = "/functional/hardReferrerTestObj"; + $hardReferrerTestObj->name = "hardReferrerTestObj"; + + + $weakReferrerRefTestObj = new WeakReferrerRefTestObj(); + $weakReferrerRefTestObj->id = "/functional/weakReferrerRefTestObj"; + $weakReferrerRefTestObj->name = "weakReferrerRefTestObj"; + + $hardReferrerRefTestObj = new HardReferrerRefTestObj(); + $hardReferrerRefTestObj->id = "/functional/hardReferrerRefTestObj"; + $hardReferrerRefTestObj->name = "hardReferrerRefTestObj"; + + $allReferrerRefTestObj = new AllReferrerRefTestObj(); + $allReferrerRefTestObj->id = "/functional/allReferrerRefTestObj"; + $allReferrerRefTestObj->name = "allReferrerRefTestObj"; + + + $weakReferrerTestObj->referenceToWeak = $weakReferrerRefTestObj; + $weakReferrerTestObj->referenceToHard = $hardReferrerRefTestObj; + $weakReferrerTestObj->referenceToAll = $allReferrerRefTestObj; + + $hardReferrerTestObj->referenceToWeak = $weakReferrerRefTestObj; + $hardReferrerTestObj->referenceToHard = $hardReferrerRefTestObj; + $hardReferrerTestObj->referenceToAll = $allReferrerRefTestObj; + + $this->dm->persist($weakReferrerTestObj); + $this->dm->persist($hardReferrerTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $weakReferrerRefTestObj = $this->dm->find(null, "/functional/weakReferrerRefTestObj"); + $this->assertEquals(count($weakReferrerRefTestObj->referrers), 1); + $this->assertEquals($weakReferrerRefTestObj->referrers[0]->name, "weakReferrerTestObj"); + + $hardReferrerRefTestObj = $this->dm->find(null, "/functional/hardReferrerRefTestObj"); + $this->assertEquals(count($hardReferrerRefTestObj->referrers), 1); + $this->assertEquals($hardReferrerRefTestObj->referrers[0]->name, "hardReferrerTestObj"); + + $allReferrerRefTestObj = $this->dm->find(null, "/functional/allReferrerRefTestObj"); + $this->assertEquals(count($allReferrerRefTestObj->referrers), 2); + + $tmpNames = array(); + foreach ($allReferrerRefTestObj->referrers as $referrer) { + $tmpNames[] = $referrer->name; + } + + $names = array("weakReferrerTestObj", "hardReferrerTestObj"); + foreach ($names as $name) { + $this->assertTrue(in_array($name, $tmpNames)); + } + } + + public function testNamedRef() + { + $referrerTestObj = new ReferrerTestObj(); + $referrerNamedPropTestObj = new ReferrerNamedPropTestObj(); + + $allReferrerRefNamedPropTestObj = new AllReferrerRefNamedPropTestObj(); + + $referrerTestObj->id = "/functional/referrerTestObj"; + $referrerTestObj->name = "referrerTestObj"; + + $referrerNamedPropTestObj->id = "/functional/referrerNamedPropTestObj"; + $referrerNamedPropTestObj->name = "referrerNamedPropTestObj"; + + $allReferrerRefNamedPropTestObj->id = "/functional/allReferrerRefNamedPropTestObj"; + $allReferrerRefNamedPropTestObj->name = "referenced"; + + $referrerTestObj->reference = $allReferrerRefNamedPropTestObj; + $referrerNamedPropTestObj->namedReference = $allReferrerRefNamedPropTestObj; + + $this->dm->persist($referrerTestObj); + $this->dm->persist($referrerNamedPropTestObj); + $this->dm->flush(); + $this->dm->clear(); + + $reference = $this->dm->find(null, "/functional/allReferrerRefNamedPropTestObj"); + + $this->assertEquals(count($reference->referrers), 1); + $this->assertEquals($reference->referrers[0]->name, "referrerNamedPropTestObj"); + } +} + +/** + * @PHPCRODM\Document(alias="HardReferrerTestObj") + */ +class HardReferrerTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\ReferenceOne(targetDocument="HardReferrerRefTestObj", weak=false) */ + public $referenceToHard; + /** @PHPCRODM\ReferenceOne(targetDocument="WeakReferrerRefTestObj", weak=false) */ + public $referenceToWeak; + /** @PHPCRODM\ReferenceOne(targetDocument="AllReferrerRefTestObj", weak=false) */ + public $referenceToAll; + /** @PHPCRODM\String */ + public $name; +} + +/** + * @PHPCRODM\Document(alias="WeakReferrerTestObj") + */ +class WeakReferrerTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\ReferenceOne(targetDocument="WeakReferrerRefTestObj", weak=true) */ + public $referenceToWeak; + /** @PHPCRODM\ReferenceOne(targetDocument="HardReferrerRefTestObj", weak=true) */ + public $referenceToHard; + /** @PHPCRODM\ReferenceOne(targetDocument="AllReferrerRefTestObj", weak=true) */ + public $referenceToAll; + /** @PHPCRODM\String */ + public $name; +} + +/** + * @PHPCRODM\Document(alias="WeakReferrerRefTestObj", referenceable="true") + */ +class WeakReferrerRefTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\Referrers(referenceType="weak") */ + public $referrers; + /** @PHPCRODM\String */ + public $name; +} + +/** + * @PHPCRODM\Document(alias="HardReferrerRefTestObj", referenceable="true") + */ +class HardReferrerRefTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\Referrers(referenceType="hard") */ + public $referrers; + /** @PHPCRODM\String */ + public $name; +} + +/** + * @PHPCRODM\Document(alias="AllReferrerRefTestObj", referenceable="true") + */ +class AllReferrerRefTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\Referrers() */ + public $referrers; + /** @PHPCRODM\String */ + public $name; +} + +/** + * @PHPCRODM\Document(alias="AllReferrerRefNamedPropTestObj", referenceable="true") + */ +class AllReferrerRefNamedPropTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\Referrers(filterName="namedReference") */ + public $referrers; + /** @PHPCRODM\String */ + public $name; } /** @@ -375,10 +596,23 @@ class ReferrerTestObj public $id; /** @PHPCRODM\String */ public $name; - /** @PHPCRODM\ReferenceOne(targetDocument="ReferrerRefTestObj", weak=false) */ + /** @PHPCRODM\ReferenceOne(targetDocument="ReferrerRefTestObj") */ public $reference; } +/** + * @PHPCRODM\Document(alias="ReferrerNamedPropTestObj") + */ +class ReferrerNamedPropTestObj +{ + /** @PHPCRODM\Id */ + public $id; + /** @PHPCRODM\String */ + public $name; + /** @PHPCRODM\ReferenceOne(targetDocument="ReferrerRefTestObj") */ + public $namedReference; +} + /** * @PHPCRODM\Document(alias="ReferrerRefTestObj", referenceable="true") */ @@ -388,6 +622,6 @@ class ReferrerRefTestObj public $id; /** @PHPCRODM\String */ public $name; - /** @PHPCRODM\Referrers */ + /** @PHPCRODM\Referrers() */ public $referrers; }