Permalink
Browse files

removed option "all" for referenceType, new test, text fixes

  • Loading branch information...
1 parent 5fb699f commit f11fcf86c107fdb794fc7cfb90056025e5563d02 Johannes Stark committed Aug 24, 2011
@@ -95,7 +95,7 @@ class Children extends Annotation
class Referrers extends Annotation
{
public $filterName = null;
- public $referenceType = "all";
+ public $referenceType = null;
}
final class EmbeddedDocument extends Annotation {}
@@ -535,8 +535,8 @@ public function mapReferrers(array $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'.");
+ if (!(array_key_exists('referenceType', $mapping) && in_array($mapping['referenceType'], array(null, "weak", "hard")))) {
+ throw new MappingException("You have to specify a 'referenceType' for the '" . $this->name . "' association which must be null, 'weak' or 'hard'.");
}
return $mapping;
}
@@ -15,7 +15,7 @@ class ReferrersCollection extends PersistentCollection
private $dm;
private $name;
- public function __construct($document, DocumentManager $dm, $type = "all", $name = null)
+ public function __construct($document, DocumentManager $dm, $type = null, $name = null)
{
$this->document = $document;
$this->dm = $dm;
@@ -309,8 +309,6 @@ public function createDocument($documentName, $node, array &$hints = array())
}
}
-
-
foreach ($class->childMappings as $childName => $mapping) {
if ($node->hasNode($mapping['name'])) {
$documentState[$class->childMappings[$childName]['fieldName']] = $this->createDocument(null, $node->getNode($mapping['name']));
@@ -469,14 +467,9 @@ private function cascadeScheduleInsert($class, $document, &$visited)
foreach ($class->referrersMappings as $referrerName => $mapping) {
$referrer = $class->reflFields[$referrerName]->getValue($document);
if ($referrer !== null && $this->getDocumentState($referrer) == self::STATE_NEW) {
- //$referrerClass = $this->dm->getClassMetadata(get_class($referrer));
- //$id = $class->reflFields[$class->identifier]->getValue($document);
- //$referrerClass->reflFields[$referrerClass->identifier]->setValue($referrer, $id . '/'. $mapping['name']);
- //$this->doScheduleInsert($referrer, $visited, ClassMetadata::GENERATOR_TYPE_ASSIGNED);
$this->doScheduleInsert($referrer, $visited);
}
}
-
}
private function getIdGenerator($type)
@@ -525,8 +518,6 @@ private function purgeChildren($document)
$this->removeFromIdentityMap($child);
}
}
-
-
}
public function getDocumentState($document)
@@ -710,11 +701,10 @@ private function computeReferrerChanges($mapping, $referrer, $referenceId)
} else if ($state == self::STATE_DETACHED) {
// TODO: can this actually happen?
throw new \InvalidArgumentException("A detached document was found through a "
- . "reference during cascading a persist operation.");
+ . "referrer during cascading a persist operation.");
}
}
-
/**
* Gets the changeset for an document.
*
@@ -1153,15 +1143,21 @@ public function getChildren($document, $filter = null)
}
/**
- * Get the documents that refer a given document using an optional name.
+ * Get all the documents that refer a given document using an optional name
+ * and an optional reference type.
*
- * This methods gets all nodes as a collection of documents that refer the
- * given document and matches a given name.
+ * This methods gets all nodes as a collection of documents that refer (weak
+ * and hard) the given document. The property of the referrer node that referes
+ * the document needs to match the given name and must store a reference of the
+ * given type.
* @param $document document instance which referrers should be loaded
- * @param string|array $name optional name to match on referrers names
+ * @param string $type optional type of the reference the referrer should have
+ * ("weak" or "hard")
+ * @param string $name optional name to match on referrers reference property
+ * name
* @return a collection of referrer documents
*/
- public function getReferrers($document, $type = "all", $name = null)
+ public function getReferrers($document, $type = null, $name = null)
{
$oid = spl_object_hash($document);
$node = $this->nodesMap[$oid];
@@ -1170,7 +1166,7 @@ public function getReferrers($document, $type = "all", $name = null)
$referrerPropertiesW = array();
$referrerPropertiesH = array();
- if ($type === "all") {
+ if ($type === null) {
$referrerPropertiesW = $node->getWeakReferences($name);
$referrerPropertiesH = $node->getReferences($name);
} elseif ($type === "weak") {

0 comments on commit f11fcf8

Please sign in to comment.