示例#1
0
 /**
  * @param PersistentCollection $collection
  *
  * @return Query
  */
 public function createReferenceManyInverseSideQuery(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $owner = $collection->getOwner();
     $ownerClass = $this->dm->getClassMetadata(get_class($owner));
     $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
     $mappedByMapping = isset($targetClass->fieldMappings[$mapping['mappedBy']]) ? $targetClass->fieldMappings[$mapping['mappedBy']] : array();
     $mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'] . '.$id';
     $criteria = $this->cm->merge(array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)), $this->dm->getFilterCollection()->getFilterCriteria($targetClass), isset($mapping['criteria']) ? $mapping['criteria'] : array());
     $criteria = $this->uow->getDocumentPersister($mapping['targetDocument'])->prepareQueryOrNewObj($criteria);
     $qb = $this->dm->createQueryBuilder($mapping['targetDocument'])->setQueryArray($criteria);
     if (isset($mapping['sort'])) {
         $qb->sort($mapping['sort']);
     }
     if (isset($mapping['limit'])) {
         $qb->limit($mapping['limit']);
     }
     if (isset($mapping['skip'])) {
         $qb->skip($mapping['skip']);
     }
     if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
         $qb->slaveOkay(true);
     }
     if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
         $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
     }
     return $qb->getQuery();
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     $count = $this->coll->count();
     // If this collection is inversed and not initialized, add the count returned from the database
     if ($this->mapping['isInverseSide'] && !$this->initialized) {
         $documentPersister = $this->uow->getDocumentPersister(get_class($this->owner));
         $count += empty($this->mapping['repositoryMethod']) ? $documentPersister->createReferenceManyInverseSideQuery($this)->count() : $documentPersister->createReferenceManyWithRepositoryMethodCursor($this)->count();
     }
     return count($this->mongoData) + $count;
 }
示例#3
0
 /**
  * Wrapper method for MongoCursor::sort().
  *
  * Field names will be prepared according to the document mapping.
  *
  * @see CursorInterface::sort()
  * @see http://php.net/manual/en/mongocursor.sort.php
  * @param array $fields
  * @return self
  */
 public function sort($fields)
 {
     $fields = $this->unitOfWork->getDocumentPersister($this->class->name)->prepareSortOrProjection($fields);
     $this->baseCursor->sort($fields);
     return $this;
 }
示例#4
0
 protected function getDocumentPersister()
 {
     return $this->uow->getDocumentPersister($this->documentName);
 }
示例#5
0
 /**
  * @param object $document
  * @return boolean
  */
 private function isScheduledForInsert($document)
 {
     return $this->uow->isScheduledForInsert($document) || $this->uow->getDocumentPersister(get_class($document))->isQueuedForInsert($document);
 }