Skip to content

[5.2] Fix eager loading within global scopes#11779

Closed
acasar wants to merge 1 commit intolaravel:5.2from
acasar:global-scope-relation
Closed

[5.2] Fix eager loading within global scopes#11779
acasar wants to merge 1 commit intolaravel:5.2from
acasar:global-scope-relation

Conversation

@acasar
Copy link
Copy Markdown
Contributor

@acasar acasar commented Jan 8, 2016

Fixes #11764

I don't really like that we call applyScopes twice now (once for query execution and once for eager loading), but since both getModels() and eagerLoadRelations() are public, any other solution would be backwards incompatible (we'd need to pass the builder into both methods). I can refactor this for 5.3.

@acasar
Copy link
Copy Markdown
Contributor Author

acasar commented Jan 8, 2016

Hmm.. On the second thought I don't know if that's really necessary. I mean we have $with property on the model to do eager loading.

@joshbodine21 Any particular reason why you want to do it in a global scope?

@joshbodine21
Copy link
Copy Markdown

@acasar In the end, I am trying to use a trait to boot the global scope in more than one model. This is for a REST API and I am filtering the request in some middleware to get the relationships that the user wants to include the endpoint for any given model. I can't use the $with property on the model because I want the user to specify which relationships they want. I just figured what I could do in a local scope I could do in a global one too. Am I looking at this in the wrong way?

@acasar
Copy link
Copy Markdown
Contributor Author

acasar commented Jan 8, 2016

Alternative solution that only calls applyScopes once per query: acasar@dd6a9f1

@taylorotwell should I PR that instead?

@taylorotwell
Copy link
Copy Markdown
Member

Submit which ever one you think is best. If you think the other one is better then close this one and submit that one.

@acasar
Copy link
Copy Markdown
Contributor Author

acasar commented Jan 9, 2016

Replaced by #11793.

@acasar acasar closed this Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants