Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * @param ClassMetadata $class
  * @return array
  */
 private function prepareIndexes(ClassMetadata $class)
 {
     $persister = $this->dm->getUnitOfWork()->getDocumentPersister($class->name);
     $indexes = $class->getIndexes();
     $newIndexes = array();
     foreach ($indexes as $index) {
         $newIndex = array('keys' => array(), 'options' => $index['options']);
         foreach ($index['keys'] as $key => $value) {
             $key = $persister->prepareFieldName($key);
             if ($class->hasField($key)) {
                 $mapping = $class->getFieldMapping($key);
                 $newIndex['keys'][$mapping['name']] = $value;
             } else {
                 $newIndex['keys'][$key] = $value;
             }
         }
         $newIndexes[] = $newIndex;
     }
     return $newIndexes;
 }