Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing more failing tests

  • Loading branch information...
commit bb2f6f60b110c2a7c088a1f4ee698162f7a23505 1 parent dc8efcc
@lorenzo lorenzo authored
View
22 src/ORM/EagerLoader.php
@@ -14,6 +14,8 @@
*/
namespace Cake\ORM;
+use Cake\Database\Statement\BufferedStatement;
+use Cake\Database\Statement\CallbackStatement;
use Cake\ORM\Table;
use Cake\ORM\Query;
use Closure;
@@ -261,19 +263,31 @@ protected function _resolveJoins($associations) {
* directly in this query and will setup the required extra queries for fetching
* the extra data.
*
- * @param Statement $statement original query statement
+ * @param \Cake\ORM\Query $query The query for which to eage load external
+ * associations
+ * @param Statement $statement The statement created after executing the $query
* @return CallbackStatement $statement modified statement with extra loaders
*/
- public function eagerLoad($statement) {
+ public function eagerLoad($query, $statement) {
+ if (!$this->hasExternal($query->repository())) {
+ return $statement;
+ }
+
+ $driver = $query->connection()->driver();
+
+ if (!($statement instanceof BufferedStatement)) {
+ $statement = new BufferedStatement($statement, $driver);
+ }
+
$collected = $this->_collectKeys($statement);
foreach ($this->_loadEagerly as $meta) {
$contain = $meta['associations'];
$alias = $meta['instance']->source()->alias();
$keys = isset($collected[$alias]) ? $collected[$alias] : null;
$f = $meta['instance']->eagerLoader(
- $meta['config'] + ['query' => $this, 'contain' => $contain, 'keys' => $keys]
+ $meta['config'] + ['query' => $query, 'contain' => $contain, 'keys' => $keys]
);
- $statement = new CallbackStatement($statement, $this->connection()->driver(), $f);
+ $statement = new CallbackStatement($statement, $driver, $f);
}
return $statement;
View
13 src/ORM/Query.php
@@ -16,8 +16,6 @@
use Cake\Collection\Iterator\MapReduce;
use Cake\Database\Query as DatabaseQuery;
-use Cake\Database\Statement\BufferedStatement;
-use Cake\Database\Statement\CallbackStatement;
use Cake\Event\Event;
use Cake\ORM\EagerLoader;
use Cake\ORM\QueryCacher;
@@ -903,16 +901,7 @@ protected function _decorateResults($result) {
*/
protected function _decorateStatement($statement) {
$statement = parent::_decorateStatement($statement);
- $loader = $this->eagerLoader();
-
- if ($loader->hasExternal($this->repository())) {
- if (!($statement instanceof BufferedStatement)) {
- $statement = new BufferedStatement($statement, $this->connection()->driver());
- }
- $statement = $loader->eagerLoad($statement);
- }
-
- return $statement;
+ return $this->eagerLoader()->eagerLoad($this, $statement);
}
/**
View
3  src/ORM/ResultSet.php
@@ -284,8 +284,7 @@ public function count() {
* @return void
*/
protected function _calculateAssociationMap() {
- $contain = $this->_query->normalizedContainments();
-
+ $contain = $this->_query->eagerLoader()->normalized($this->_defaultTable);
if (!$contain) {
return;
}

0 comments on commit bb2f6f6

Please sign in to comment.
Something went wrong with that request. Please try again.