Skip to content

Commit

Permalink
Fixes #7591
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 6, 2015
1 parent 1f4a428 commit 25417ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/ORM/Association.php
Expand Up @@ -771,13 +771,11 @@ protected function _bindNewAssociations($query, $surrogate, $options)
$loader = $surrogate->eagerLoader();
$contain = $loader->contain();
$matching = $loader->matching();
$target = $this->_targetTable;

if (!$contain && !$matching) {
return;
}

$loader->attachAssociations($query, $target, $options['includeFields']);
$newContain = [];
foreach ($contain as $alias => $value) {
$newContain[$options['aliasPath'] . '.' . $alias] = $value;
Expand Down
24 changes: 16 additions & 8 deletions src/ORM/EagerLoader.php
Expand Up @@ -334,14 +334,22 @@ public function attachAssociations(Query $query, Table $repository, $includeFiel
return;
}

foreach ($this->attachableAssociations($repository) as $loadable) {
$config = $loadable->config() + [
'aliasPath' => $loadable->aliasPath(),
'propertyPath' => $loadable->propertyPath(),
'includeFields' => $includeFields,
];
$loadable->instance()->attachTo($query, $config);
}
$attachable = $this->attachableAssociations($repository);
$processed = [];
do {
foreach ($attachable as $alias => $loadable) {
$config = $loadable->config() + [
'aliasPath' => $loadable->aliasPath(),
'propertyPath' => $loadable->propertyPath(),
'includeFields' => $includeFields,
];
$loadable->instance()->attachTo($query, $config);
$processed[$alias] = true;
}

$newAttachable = $this->attachableAssociations($repository);
$attachable = array_diff_key($newAttachable, $processed);
} while ($attachable);
}

/**
Expand Down

0 comments on commit 25417ec

Please sign in to comment.