From a8b1048577ed2c987cf05d1951548d1c4c8da54b Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 28 Dec 2013 21:05:14 +0100 Subject: [PATCH] Making ResultSet::first() return the first result if it was buffered, it makes no sense to return null if we have the value already --- Cake/ORM/ResultSet.php | 4 ++++ Cake/Test/TestCase/ORM/ResultSetTest.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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()); } /**