Skip to content

Commit

Permalink
Making ResultSet::first() return the first result if it was buffered, it
Browse files Browse the repository at this point in the history
makes no sense to return null if we have the value already
  • Loading branch information
lorenzo committed Dec 28, 2013
1 parent b2d204e commit a8b1048
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cake/ORM/ResultSet.php
Expand Up @@ -214,6 +214,10 @@ public function valid() {
* @return array|object
*/
public function first() {
if (isset($this->_results[0])) {
return $this->_results[0];
}

if ($this->valid()) {
if ($this->_statement) {
$this->_statement->closeCursor();
Expand Down
4 changes: 2 additions & 2 deletions Cake/Test/TestCase/ORM/ResultSetTest.php
Expand Up @@ -182,8 +182,8 @@ public function testFirstAfterSerialize() {
$row = $results->first();
$this->assertEquals($this->fixtureData[0], $row);

$this->assertNull($results->first(), 'No more rows.');
$this->assertNull($results->first(), 'No more rows.');
$this->assertSame($row, $results->first());
$this->assertSame($row, $results->first());
}

/**
Expand Down

0 comments on commit a8b1048

Please sign in to comment.