public function execute(array $options = array())
{
$uow = $this->dm->getUnitOfWork();
$results = $this->query->execute($options);
// Convert the regular mongodb cursor to the odm cursor
if ($results instanceof BaseCursor) {
$cursor = $results->getMongoCursor();
$results = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
$results->hydrate($this->hydrate);
}
// GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
// iterator over it and hydrate each object.
if ($this->query instanceof \Doctrine\MongoDB\Query\GeoLocationFindQuery && $this->hydrate) {
foreach ($results as $key => $result) {
$document = $result['obj'];
if ($this->class->distance) {
$document[$this->class->distance] = $result['dis'];
}
$results[$key] = $uow->getOrCreateDocument($this->class->name, $document);
}
$results->reset();
}
if ($this->hydrate && ($this->query instanceof FindAndRemoveQuery || $this->query instanceof FindAndUpdateQuery) && is_array($results) && isset($results['_id'])) {
// Convert a single document array to a document object
$results = $uow->getOrCreateDocument($this->class->name, $results);
}
return $results;
}