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

feat: add Model.{getInitialModel,withoutScope}, rename schema+(un)?scope #14337

Merged
merged 8 commits into from
Apr 10, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Apr 7, 2022

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • Does yarn test or yarn test-DIALECT pass with this change (including linting)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

Another building block for #14280

Context:
Model.scope, Model.unscope and Model.schema return new classes.
This is a problem for the above PR because that PR needs to be able to check whether two models classes are the same.

This PR does a few things:

  • Deduplicate models generated by these 3 methods. Which means that Model.schema('public') === Model.schema('public')
  • Adds Model.withInitialScope: unscope() is a misnomer, it doesn't restore the model to its state before the call to scope(). Instead it returns a model with no scope at all (including the default scope). withInitialScope() does return a model with the default scope.
  • Adds Model.getInitialModel which returns the model, like it was before any call to scope, unscope or schema
  • Renames unscope to withoutScope, scope to withScope and schema to withSchema.
    This change was done to signal that these methods will not mutate the Model and, instead, return a new Model. These names follow conventions for similar methods that we can find in other libraries.
    The old names still exist but will log a deprecation notice. There are no breaking changes in this PR.

@ephys ephys added the type: feature For issues and PRs. For new features. Never breaking changes. label Apr 7, 2022
@ephys ephys self-assigned this Apr 7, 2022
@ephys ephys requested a review from a team April 8, 2022 20:32
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Looks good! I'm assuming the documentation of the renames will follow later?

@ephys
Copy link
Member Author

ephys commented Apr 10, 2022

In our upgrade guide? Yep :)

@ephys ephys merged commit 338766b into main Apr 10, 2022
@ephys ephys deleted the ephys/model-variants branch April 10, 2022 16:07
@ephys ephys mentioned this pull request Apr 11, 2022
6 tasks
@github-actions
Copy link
Contributor

🎉 This PR is included in version 7.0.0-alpha.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @v7 type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants