Skip to content

Commit

Permalink
Association formatter should not invoke the entity get method
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jun 22, 2016
1 parent ecb3964 commit b440bb1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ORM/Association.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\ORM;

use Cake\Collection\Collection;
use Cake\Core\ConventionsTrait;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\EntityInterface;
Expand Down Expand Up @@ -774,8 +775,20 @@ protected function _formatAssociationResults($query, $surrogate, $options)
}

$property = $options['propertyPath'];
$query->formatResults(function ($results) use ($formatters, $property) {
$extracted = $results->extract($property)->compile();
$propertyPath = explode('.', $property);
$query->formatResults(function ($results) use ($formatters, $property, $propertyPath) {
$extracted = [];
foreach ($results as $result) {
foreach ($propertyPath as $propertyPathItem) {
if (!isset($result[$propertyPathItem])) {
$result = null;
break;
}
$result = $result[$propertyPathItem];
}
$extracted[] = $result;
}
$extracted = new Collection($extracted);
foreach ($formatters as $callable) {
$extracted = new ResultSetDecorator($callable($extracted));
}
Expand Down

0 comments on commit b440bb1

Please sign in to comment.