Browse Source

Hadling ResultSet::first() trhough collection functions

In the past we had to handle the first() function differently so we
could close the statement. Doe to improvemets in how the statement
is closed in te query and the connection, this is no loger required.
Jose Lorenzo Rodriguez 11 years ago
parent
commit
902102f94e
2 changed files with 13 additions and 27 deletions
  1. 0 27
      src/ORM/ResultSet.php
  2. 13 0
      tests/TestCase/ORM/QueryRegressionTest.php

+ 0 - 27
src/ORM/ResultSet.php

@@ -248,33 +248,6 @@ class ResultSet implements ResultSetInterface {
 	}
 
 /**
- * Returns the first result in this set and blocks the set so that no other
- * results can be fetched.
- *
- * When using serialized results, the index will be incremented past the
- * end of the results simulating the behavior when the result set is backed
- * by a statement.
- *
- * @return array|object|null
- */
-	public function first() {
-		if (isset($this->_results[0])) {
-			return $this->_results[0];
-		}
-
-		if ($this->valid()) {
-			if ($this->_statement) {
-				$this->_statement->closeCursor();
-			}
-			if (!$this->_statement && $this->_results) {
-				$this->_index = count($this->_results);
-			}
-			return $this->_current;
-		}
-		return null;
-	}
-
-/**
  * Gives the number of rows in the result set.
  *
  * Part of the Countable interface.

+ 13 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -563,4 +563,17 @@ class QueryRegressionTest extends TestCase {
 		$this->assertCount(3, $results);
 	}
 
+/**
+ * Tests that calling first on the query results will not remove all other results
+ * from the set.
+ *
+ * @return void
+ */
+	public function testFirstOnResultSet() {
+		$results = TableRegistry::get('Articles')->find()->all();
+		$this->assertEquals(3, $results->count());
+		$this->assertNotNull($results->first());
+		$this->assertCount(3, $results->toArray());
+	}
+
 }