Skip to content

[9.x] Restore v8 behaviour of base query for relations - #41923

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
tpetry:relationship-base
Apr 11, 2022
Merged

[9.x] Restore v8 behaviour of base query for relations#41923
taylorotwell merged 1 commit into
laravel:9.xfrom
tpetry:relationship-base

Conversation

@tpetry

@tpetry tpetry commented Apr 11, 2022

Copy link
Copy Markdown
Contributor

As commented on #41918 I found a new inconsistency in the Laravel 8.x and 9.x implementation with the fix by @driesvints.

In Laravel v8 the implementation for getBaseQuery was:

public function getBaseQuery()
{
    return $this->query->getQuery();
}

With the recently merged fix it's now the following which is different (it's now applying the scope!):

public function getBaseQuery()
{
    return $this->toBase();
}

public function toBase()
{
    return $this->query->applyScopes()->getQuery();
}

I restored the exact behavior of Laravel 8.x that getBaseQuery and toBase are both operating directly on the Eloquent\Builder object. So any change in Eloquent\Builder::toBase() is also automatically reflected on Relationship::toBase() as in Laravel 8.x.

@driesvints driesvints left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably indeed is the better fix. Thanks @tpetry.

Comment thread src/Illuminate/Database/Eloquent/Relations/Relation.php
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.

3 participants