Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Fix MorphTo lazy loading and withoutGlobalScopes() #25406

Merged
merged 1 commit into from
Sep 2, 2018
Merged

[5.6] Fix MorphTo lazy loading and withoutGlobalScopes() #25406

merged 1 commit into from
Sep 2, 2018

Conversation

staudenmeir
Copy link
Contributor

#25331 fixed withoutGlobalScopes() when eager loading MorphTo relationships.
This broke lazy loading:

class Comment extends Model
{
    public function commentable()
    {
        return $this->morphTo()->withoutGlobalScopes();
    }
}

class Post extends Model
{
    use SoftDeletes;
}

Comment::first()->commentable;
# expected
select * from "posts" where "posts"."id" = ? limit 1

# actual
select * from "posts" where "posts"."id" = ? and "posts"."deleted_at" is null limit 1

The $macroBuffer is only used for eager loading. For lazy loading, we have to pass withoutGlobalScopes() through to the query.

Fixes #25402.

@taylorotwell taylorotwell merged commit ec81088 into laravel:5.6 Sep 2, 2018
@staudenmeir staudenmeir deleted the morph-to branch September 2, 2018 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants