Skip to content

Commit

Permalink
Merge pull request #4871 from soundrussian/4.2
Browse files Browse the repository at this point in the history
Return trashed models with morphTo() if told so on non-eager queries (fixes #4870)
  • Loading branch information
taylorotwell committed Jul 19, 2014
2 parents ae74d67 + 38e5de4 commit a76ed01
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ protected function getResultsByType($type)

$query = $instance->newQuery();

if ($this->withTrashed && $query->getMacro('withTrashed') !== null)
{
$query = $query->withTrashed();
}
$query = $this->useWithTrashed($query);

return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
}
Expand Down Expand Up @@ -216,7 +213,24 @@ public function withTrashed()
{
$this->withTrashed = true;

$this->query = $this->useWithTrashed($this->query);

return $this;
}

/**
* Return trashed models with query if told so
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function useWithTrashed(Builder $query)
{
if ($this->withTrashed && $query->getMacro('withTrashed') !== null)
{
return $query->withTrashed();
}
return $query;
}

}

0 comments on commit a76ed01

Please sign in to comment.