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.2] Refactor relations and scopes #13824

Merged
merged 3 commits into from
Jun 1, 2016
Merged

[5.2] Refactor relations and scopes #13824

merged 3 commits into from
Jun 1, 2016

Conversation

acasar
Copy link
Contributor

@acasar acasar commented Jun 1, 2016

As discussed on Slack, I refactored some stuff that was recently made overly complex by some pull requests. All in all, I managed to shave off around 100 lines of code and all tests still pass. I didn't touch any public methods so this shouldn't break anything.

Summary of scope refactoring:

  • I merged applyCallbackToQuery and callScope in a single more general method called callScope
  • I generalized mergeModelDefinedRelationWheresToHasQuery, made it public, and renamed it to mergeModelDefinedRelationConstraints so it can now be used from relations as well.
  • I managed to greatly simplify applyScopes (which applies global scopes) by utilizing the new callScope method. As a result the applyScope helper method is not needed any more.
  • Some minor refactoring of getGlobalScope on the Model to match the logic of withoutGlobalScope on the Builder.

Summary of morphTo refactoring:

  • getEagerLoadsForInstance was deleted and replaced with a call tonestedRelations on the Builder (which is now public).
  • mergeRelationWheresToMorphQuery was deleted as well. The new public Builder method mergeModelDefinedRelationConstraints is used instead.

Summary of SoftDeletes refactoring:

  • I deleted withTrashed and onlyTrashed static helpers from the SoftDeletes trait, since the call is redirected to query macro anyway.

@taylorotwell taylorotwell merged commit c9d9748 into laravel:5.2 Jun 1, 2016
@taylorotwell
Copy link
Member

Thanks ❤️

@lemesdaniel
Copy link

Hello,

@acasar, How do I recover deleted records now? Before I used onlyTrashed?

Thanks

@acasar
Copy link
Contributor Author

acasar commented Jun 23, 2016

@lemesdaniel exactly the same as before. If you're having any problems let me know.

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