Skip to content
Permalink
Browse files

Avoiding first results sweep if not required for eagerly loading

associations
  • Loading branch information...
lorenzo committed May 20, 2013
1 parent cc4be72 commit 22ddc11359056daa2dca665dad0bbfe39830989b
Showing with 13 additions and 8 deletions.
  1. +13 −8 lib/Cake/ORM/Query.php
@@ -228,25 +228,30 @@ protected function _eagerLoad($statement) {
$collectKeys = [];
foreach ($this->_loadEagerly as $association => $meta) {
$source = $meta['instance']->source();
$alias = $source->alias();
$pkField = key($this->aliasField($source->primaryKey(), $alias));
$collectKeys[] = [$alias, $pkField];
if ($meta['instance']->requiresKeys($meta['config'])) {
$alias = $source->alias();
$pkField = key($this->aliasField($source->primaryKey(), $alias));
$collectKeys[] = [$alias, $pkField];
}
}
$keys = [];
while($result = $statement->fetch('assoc')) {
foreach ($collectKeys as $parts) {
$keys[$parts[0]][] = $result[$parts[1]];
if (!empty($collectKeys)) {
while($result = $statement->fetch('assoc')) {
foreach ($collectKeys as $parts) {
$keys[$parts[0]][] = $result[$parts[1]];
}
}
$statement->rewind();
}
$statement->rewind();
foreach ($this->_loadEagerly as $association => $meta) {
$contain = $meta['associations'];
$alias = $meta['instance']->source()->alias();
$f = $meta['instance']->eagerLoader(
$this,
$meta['config'] + compact('contain'),
$keys[$meta['instance']->source()->alias()]
isset($keys[$alias]) ? $keys[$alias] : null
);
$statement = new CallbackStatement($statement, $this->connection()->driver(), $f);
}

0 comments on commit 22ddc11

Please sign in to comment.
You can’t perform that action at this time.