Skip to content

Commit

Permalink
Updating Query object to support update and remove queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed May 20, 2010
1 parent 2c196dd commit 795dc99
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 78 deletions.
3 changes: 3 additions & 0 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ public function loadByID($documentName, $id)
{
$collection = $this->getDocumentCollection($documentName);
$result = $collection->findOne(array('_id' => new \MongoId($id)));
if ( ! $result) {
throw new \InvalidArgumentException(sprintf('Could not loadByID because ' . $documentName . ' '.$id . ' does not exist anymore.'));
}
return $this->load($documentName, $id, $result);
}

Expand Down
17 changes: 17 additions & 0 deletions lib/Doctrine/ODM/MongoDB/MongoCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ class MongoCursor implements \Iterator
{
/** The DocumentManager instance. */
private $_dm;

/** The UnitOfWork instance. */
private $_uow;

/** The ClassMetadata instance. */
private $_class;

/** The PHP MongoCursor being wrapped */
private $_mongoCursor;

/** Whether or not to try and hydrate the returned data */
private $_hydrate = true;

Expand Down Expand Up @@ -133,6 +137,19 @@ public function getResults()
return iterator_to_array($this);
}

/**
* Get the first single result from the cursor.
*
* @return object $document The single document.
*/
public function getSingleResult()
{
if ($results = $this->getResults()) {
return array_shift($results);
}
return null;
}

/** @proxy */
public function __call($method, $arguments)
{
Expand Down
Loading

0 comments on commit 795dc99

Please sign in to comment.