Skip to content

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

Merged
ephys merged 8 commits into
mainfrom
ephys/model-variants
Apr 10, 2022
Merged

ephys merged 8 commits into
mainfrom
ephys/model-variants

Conversation

@ephys

@ephys ephys commented Apr 7, 2022

Copy link
Copy Markdown
Member

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 DEPRECATED: replace with the "feature" issue type 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

@WikiRik WikiRik left a comment

Copy link
Copy Markdown
Member

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

ephys commented Apr 10, 2022

Copy link
Copy Markdown
Member Author

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
3 of 6 tasks
@github-actions

Copy link
Copy Markdown
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 DEPRECATED: replace with the "feature" issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants