Skip to content

[5.2] Fix eager loading within global scopes#11793

Merged
taylorotwell merged 1 commit intolaravel:5.2from
acasar:global-scope-relation-2
Jan 11, 2016
Merged

[5.2] Fix eager loading within global scopes#11793
taylorotwell merged 1 commit intolaravel:5.2from
acasar:global-scope-relation-2

Conversation

@acasar
Copy link
Copy Markdown
Contributor

@acasar acasar commented Jan 9, 2016

This replaces #11779 and fixes #11764

Changelog:

  • Builder now applies scopes in get() instead of in getModels() and uses the returned Builder instance to eager load relations, which fixes Global Scope not returning Related Model #11764
  • I also had to apply the same change on two Relation objects which were using similar pattern.

Compared to #11779, this solution is more performant since it only executes applyScopes() once per query.

@GrahamCampbell GrahamCampbell changed the title [5.2] Fix eager loading within global scopes #2 [5.2] Fix eager loading within global scopes Jan 9, 2016
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are these tests removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

k, thx

@acasar
Copy link
Copy Markdown
Contributor Author

acasar commented Jan 10, 2016

OK, managed to get those tests working too.

@taylorotwell
Copy link
Copy Markdown
Member

Can you describe what bug this fixes and what the problem was with our logic before?

@acasar
Copy link
Copy Markdown
Contributor Author

acasar commented Jan 10, 2016

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
@taylorotwell taylorotwell merged commit 22c06c5 into laravel:5.2 Jan 11, 2016
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