Skip to content

Commit

Permalink
Fixing a bug that prevented eager loads from working on hasOne and be…
Browse files Browse the repository at this point in the history
…longsTo relationships.
  • Loading branch information
joshforbes committed Jun 30, 2016
1 parent 3dffdf1 commit 7b4fc08
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Traits/QueryHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ protected function eagerLoadIncludes($model, $includes)
$builder = $model;

foreach ($includes as $include) {
if (!$model->$include) {
continue;
if (method_exists($model, $include) && $model->$include() instanceof Relation) {
$builder = $builder->with([
$include => function ($query) use ($include) {
$parameters = $this->fractal ? $this->fractal->getIncludeParams($include) : null;
$this->applyParameters($query, $parameters);
}
]);
}

$builder = $builder->with([
$include => function ($query) use ($include) {
$parameters = $this->fractal ? $this->fractal->getIncludeParams($include) : null;
$this->applyParameters($query, $parameters);
}
]);
}

return $builder;
Expand Down

0 comments on commit 7b4fc08

Please sign in to comment.