Skip to content

Commit

Permalink
Making sure beforeFind is only triggered once per query
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 17, 2014
1 parent 649570e commit 9415772
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/Datasource/QueryTrait.php
Expand Up @@ -203,13 +203,6 @@ public function all() {
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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/ORM/Query.php
Expand Up @@ -644,6 +644,11 @@ public function sql(ValueBinder $binder = null) {
* @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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/TableTest.php
Expand Up @@ -433,7 +433,7 @@ public function testFindBeforeFindEventOverrideReturn() {

$query = $table->find('all');
$query->limit(1);
$this->assertEquals($expected, $query->all());
$this->assertEquals($expected, $query->all()->toArray());
}

/**
Expand Down

0 comments on commit 9415772

Please sign in to comment.