Skip to content
Permalink
Browse files

Implemented EagerLoader::attachableAssociations(), this method will help

triggering beforeFind on associations
  • Loading branch information...
lorenzo committed Feb 2, 2014
1 parent c403827 commit 4fa3bb12cc23f5cc10a82c8d4100478ec0391060
Showing with 21 additions and 6 deletions.
  1. +21 −6 src/ORM/EagerLoader.php
@@ -244,13 +244,30 @@ public function attachAssociations(Query $query, $includeFields) {
return;
}
$contain = $this->normalized($query->repository());
foreach ($this->_resolveJoins($contain) as $options) {
$repository = $query->repository();
foreach ($this->attachableAssociations($repository) as $options) {
$config = $options['config'] + ['includeFields' => $includeFields];
$options['instance']->attachTo($query, $config);
}
}
/**
* Returns an array with the associations that can be fetched using a single query,
* the array keys are the association aliases and the values will contain an array
* with the following keys:
*
* - instance: the association object instance
* - config: the options set for fetching such association
*
* @param \Cake\ORM\Table $repository The table containing the associations to be
* attached
* @return array
*/
public function attachableAssociations(Table $repository) {
$contain = $this->normalized($repository);
return $this->_resolveJoins($contain);
}
/**
* Auxiliary function responsible for fully normalizing deep associations defined
* using `contain()`
@@ -284,10 +301,6 @@ protected function _normalizeContain(Table $parent, $alias, $options) {
$config['associations'][$t] = $this->_normalizeContain($table, $t, $assoc);
}
if (!$config['canBeJoined']) {
$this->_loadExternal[$alias] = $config;
}
return $config;
}
@@ -304,6 +317,8 @@ protected function _resolveJoins($associations) {
if ($options['canBeJoined']) {
$result[$table] = $options;
$result += $this->_resolveJoins($options['associations']);
} else {
$this->_loadExternal[$table] = $options;
}
}
return $result;

0 comments on commit 4fa3bb1

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