Skip to content

Commit

Permalink
Refactoring som code
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 9, 2014
1 parent 510232d commit 568c702
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/ORM/Association.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,26 @@ protected function _copyAttributes($query, $surrogate, $options) {
$query->select($query->aliasFields($options['fields'], $target->alias()));
}

foreach ($surrogate->formatResults() as $callable) {
$query->formatResults(function($results) use ($callable) {
$property = $this->property();
$extracted = $callable($results->extract($property))->compile();
return $results->insert($property, $extracted);
});

$this->_formatAssociationResults($query, $surrogate, $options);
$this->_bindNewAssociations($query, $surrogate, $options);
}

protected function _formatAssociationResults($query, $surrogate, $options) {
$formatters = $surrogate->formatResults();

if (!$formatters) {
return;
}

$this->_bindNewAssociations($query, $surrogate, $options);
$query->formatResults(function($results) use ($formatters) {
$property = $this->property();
$extracted = $results->extract($property)->compile();
foreach ($formatters as $callable) {
$extracted = new ResultSetDecorator($callable($extracted));
}
return $results->insert($property, $extracted);
});
}

protected function _bindNewAssociations($query, $surrogate, $options) {
Expand Down

0 comments on commit 568c702

Please sign in to comment.