Skip to content

Commit

Permalink
Query: Added first() convenince method to return the first matched en…
Browse files Browse the repository at this point in the history
…tity from given query
  • Loading branch information
vlucas committed Feb 23, 2010
1 parent 817aa7a commit 1159b83
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Query.php
Expand Up @@ -215,19 +215,29 @@ public function getIterator()


/**
* Convenience function passthrough for ResultSet
* Triggers execute() and empties current active query
* Convenience function passthrough for Collection
*
* @return array
*/
public function toArray($keyColumn = null, $valueColumn = null)
{
// Execute query and call the 'toArray' function on the ResultSet
$result = $this->execute();
return ($result !== false) ? $result->toArray($keyColumn, $valueColumn) : array();
}


/**
* Return the first entity matched by the query
*
* @return mixed phpDataMapper_Entity on success, boolean false on failure
*/
public function first()
{
$result = $this->limit(1)->execute();
return ($result !== false) ? $result->first() : false;
}


/**
* Execute and return query as a collection
*
Expand Down

0 comments on commit 1159b83

Please sign in to comment.