/** * Checks that the current field includes a reference to the supplied document. */ public function includesReferenceTo($document) { if ($this->currentField) { $mapping = $this->class->getFieldMapping($this->currentField); $dbRef = $this->dm->createDBRef($document, $mapping); if (isset($mapping['simple']) && $mapping['simple']) { $this->query[$mapping['name']]['$elemMatch'] = $dbRef; } else { $keys = array('ref' => true, 'id' => true, 'db' => true); if (isset($mapping['targetDocument'])) { unset($keys['ref'], $keys['db']); } foreach ($keys as $key => $value) { $this->query[$this->currentField]['$elemMatch']['$' . $key] = $dbRef['$' . $key]; } } } else { $dbRef = $this->dm->createDBRef($document); $this->query['$elemMatch'] = $dbRef; } return $this; }
/** * Returns the reference representation to be stored in Riak. * * If the document does not have an identifier and the mapping calls for a * simple reference, null may be returned. * * @param array $referenceMapping * @param object $document * @return array|null */ public function prepareReferencedDocumentValue(array $referenceMapping, $document) { return $this->dm->createDBRef($document, $referenceMapping); }