Permalink
Browse files

Moving the remaining ORM specific code out of QueryTrait

  • Loading branch information...
1 parent 463e310 commit d6ab39ba637437d2690708a066df895088b43d1f @lorenzo lorenzo committed Feb 20, 2014
Showing with 18 additions and 4 deletions.
  1. +8 −4 src/Datasource/QueryTrait.php
  2. +10 −0 src/ORM/Query.php
View
12 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);
}
@@ -313,6 +310,13 @@ public function 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
*
* @param \Traversable $result Original results
View
10 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;
/**
@@ -584,6 +585,15 @@ public function 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
* in order to eager load deep associations.

0 comments on commit d6ab39b

Please sign in to comment.