Skip to content
Permalink
Browse files

Refactoring som code

  • Loading branch information...
lorenzo committed Feb 5, 2014
1 parent 510232d commit 568c70219104509e7c85e1889358f9fa1c720be1
Showing with 18 additions and 7 deletions.
  1. +18 −7 src/ORM/Association.php
@@ -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) {

0 comments on commit 568c702

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