Skip to content

Commit

Permalink
Fix MorphTo lazy loading and withoutGlobalScopes() (#25406)
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir authored and taylorotwell committed Sep 2, 2018
1 parent e095619 commit ec81088
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public function dissociate()
*/
public function withoutGlobalScopes(array $scopes = null)
{
$this->getQuery()->withoutGlobalScopes($scopes);

$this->macroBuffer[] = [
'method' => __FUNCTION__,
'parameters' => [$scopes],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public function test_without_global_scopes()
$this->assertNotNull($comments[0]->commentable);
$this->assertNotNull($comments[1]->commentable);
}

public function test_lazy_loading()
{
$comment = Comment::latest('id')->first();
$post = $comment->commentable()->withoutGlobalScopes()->first();

$this->assertNotNull($post);
}
}

class Comment extends Model
Expand Down

0 comments on commit ec81088

Please sign in to comment.