[5.2] Fix eager loading within global scopes#11793
Merged
taylorotwell merged 1 commit intolaravel:5.2from Jan 11, 2016
acasar:global-scope-relation-2
Merged
[5.2] Fix eager loading within global scopes#11793taylorotwell merged 1 commit intolaravel:5.2from acasar:global-scope-relation-2
taylorotwell merged 1 commit intolaravel:5.2from
acasar:global-scope-relation-2
Conversation
Collaborator
There was a problem hiding this comment.
Why are these tests removed?
Contributor
Author
There was a problem hiding this comment.
Basically, applyScopes clones the instance so the mock expectations break. From my original post:
"I had to delete 2 tests due to heavy mocking which can't be done on a cloned instance. And integration tests already cover that scenario, so they're not really needed."
Contributor
Author
|
OK, managed to get those tests working too. |
Member
|
Can you describe what bug this fixes and what the problem was with our logic before? |
Contributor
Author
|
If you add a global scope like this one to the Model: public function apply($builder)
{
return $builder->with('posts');
}It doesn't eager load posts in 5.2 but it did in 5.1 The problem with our logic is:
|
taylorotwell
added a commit
that referenced
this pull request
Jan 11, 2016
[5.2] Fix eager loading within global scopes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces #11779 and fixes #11764
Changelog:
get()instead of ingetModels()and uses the returned Builder instance to eager load relations, which fixes Global Scope not returning Related Model #11764Compared to #11779, this solution is more performant since it only executes
applyScopes()once per query.