示例#1
0
文件: Expr.php 项目: cosmow/riak-odm
 /**
  * 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;
 }
示例#2
0
 /**
  * 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);
 }