Skip to content

Commit

Permalink
Moving the remaining ORM specific code out of QueryTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 21, 2014
1 parent 463e310 commit d6ab39b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Datasource/QueryTrait.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
*
Expand Down
10 changes: 10 additions & 0 deletions src/ORM/Query.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6ab39b

Please sign in to comment.