Browse Source

Making sure beforeFind is only triggered once per query

Jose Lorenzo Rodriguez 11 years ago
parent
commit
94157726a0
3 changed files with 6 additions and 8 deletions
  1. 0 7
      src/Datasource/QueryTrait.php
  2. 5 0
      src/ORM/Query.php
  3. 1 1
      tests/TestCase/ORM/TableTest.php

+ 0 - 7
src/Datasource/QueryTrait.php

@@ -203,13 +203,6 @@ trait QueryTrait {
 			return $this->_results;
 		}
 
-		$table = $this->repository();
-		$table->dispatchEvent('Model.beforeFind', [$this, $this->_options, !$this->eagerLoaded()]);
-
-		if (isset($this->_results)) {
-			return $this->_results;
-		}
-
 		if ($this->_cache) {
 			$results = $this->_cache->fetch($this);
 		}

+ 5 - 0
src/ORM/Query.php

@@ -644,6 +644,11 @@ class Query extends DatabaseQuery implements JsonSerializable {
  * @return \Cake\ORM\ResultSet
  */
 	protected function _execute() {
+		$this->triggerBeforeFind();
+		if ($this->_results) {
+			$decorator = $this->_decoratorClass();
+			return new $decorator($this->_results);
+		}
 		$statement = $this->eagerLoader()->loadExternal($this, $this->execute());
 		return new ResultSet($this, $statement);
 	}

+ 1 - 1
tests/TestCase/ORM/TableTest.php

@@ -433,7 +433,7 @@ class TableTest extends TestCase {
 
 		$query = $table->find('all');
 		$query->limit(1);
-		$this->assertEquals($expected, $query->all());
+		$this->assertEquals($expected, $query->all()->toArray());
 	}
 
 /**