diff --git a/src/Datasource/QueryTrait.php b/src/Datasource/QueryTrait.php index 1fa1494f22c..804f4bc8da5 100644 --- a/src/Datasource/QueryTrait.php +++ b/src/Datasource/QueryTrait.php @@ -19,7 +19,6 @@ use Cake\Datasource\RepositoryInterface; use Cake\Datasource\ResultSetDecorator; use Cake\Event\Event; -use Cake\ORM\ResultSet; /** * Contains the characteristics for an object that is attached to a repository and @@ -189,9 +188,7 @@ public function all() { $results = $this->_cache->fetch($this); } if (!isset($results)) { - $results = $this->_decorateResults( - new ResultSet($this, $this->execute()) - ); + $results = $this->_decorateResults($this->_execute()); if ($this->_cache) { $this->_cache->store($this, $results); } @@ -312,6 +309,13 @@ public function first() { return $this->all()->first(); } +/** + * Executes this query and returns a traversable object containing the results + * + * @return \Traversable + */ + abstract protected function _execute(); + /** * Decorates the results iterator with MapReduce routines and formatters * diff --git a/src/ORM/Query.php b/src/ORM/Query.php index 9b82485c93d..ceed1fa8efb 100644 --- a/src/ORM/Query.php +++ b/src/ORM/Query.php @@ -17,6 +17,7 @@ use Cake\Database\Query as DatabaseQuery; use Cake\Datasource\QueryTrait; use Cake\ORM\EagerLoader; +use Cake\ORM\ResultSet; use Cake\ORM\Table; /** @@ -583,6 +584,15 @@ public function all() { return $this->_all(); } +/** + * Executes this query and returns a ResultSet object containing the results + * + * @return \Cake\ORM\ResultSet + */ + protected function _execute() { + return new ResultSet($this, $this->execute()); + } + /** * Auxiliary function used to wrap the original statement from the driver with * any registered callbacks. This will also setup the correct statement class