Skip to content

Commit

Permalink
Use keyBy instead of flatMap (#13777)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber authored and taylorotwell committed May 30, 2016
1 parent 4d03be9 commit 0f66352
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ protected function getResultsByType($type)
*/
protected function getEagerLoadsForInstance(Model $instance)
{
$eagers = BaseCollection::make($this->query->getEagerLoads());
$relations = BaseCollection::make($this->query->getEagerLoads());

return $eagers->filter(function ($constraint, $relation) {
return $relations->filter(function ($constraint, $relation) {
return Str::startsWith($relation, $this->relation.'.');
})->flatMap(function ($constraint, $relation) {
return [Str::replaceFirst($this->relation.'.', '', $relation) => $constraint];
})->keyBy(function ($constraint, $relation) {
return Str::replaceFirst($this->relation.'.', '', $relation);
})->merge($instance->getEagerLoads())->all();
}

Expand Down

0 comments on commit 0f66352

Please sign in to comment.