diff --git a/Cake/ORM/ResultSet.php b/Cake/ORM/ResultSet.php index 3497d103338..12c62cad1fb 100644 --- a/Cake/ORM/ResultSet.php +++ b/Cake/ORM/ResultSet.php @@ -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(); diff --git a/Cake/Test/TestCase/ORM/ResultSetTest.php b/Cake/Test/TestCase/ORM/ResultSetTest.php index 0b0923b6524..fa27c1a4869 100644 --- a/Cake/Test/TestCase/ORM/ResultSetTest.php +++ b/Cake/Test/TestCase/ORM/ResultSetTest.php @@ -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()); } /**