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(types): make Model.init aware of pre-configured foreign keys #14148

Merged
merged 8 commits into from Mar 22, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Feb 20, 2022

This PR is for Sequelize v7, #14370 is v6

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

Closes #14125

Model.init currently requires a configuration for every declared attributes.

Some attributes don't need to be configured by Model.init, these include:

  • Timestamp attributes.
  • Foreign keys added by association methods (like Project.belongsTo(User)).

I've resolved this by adding a new ForeignKey<> branded type (we're now at 3 branded types).
This type tells Model.init that the attribute doesn't need to be included.

I didn't include a solution for timestamp attributes, because the 'workaround' (which has been documented) is as simple and clearer than adding another branded type.


I've also included some documentation updates from #14091 that I want to cherry-pick in v6.

@ephys ephys added the type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. label Feb 20, 2022
@ephys ephys requested a review from a team February 20, 2022 15:39
@ephys ephys self-assigned this Feb 20, 2022
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.

Not knowledgeable enough to actually review the changes in src/model.d.ts but in general looks good. I am wondering however if we can't add some additional tests for this (apart from the one you've already added)

test/types/infer-attributes.ts Outdated Show resolved Hide resolved
test/types/infer-attributes.ts Show resolved Hide resolved
npereira-jc
npereira-jc previously approved these changes Mar 20, 2022
WikiRik
WikiRik previously approved these changes Mar 21, 2022
@ephys ephys dismissed stale reviews from WikiRik and npereira-jc via 2b6531f March 22, 2022 08:45
@ephys
Copy link
Member Author

ephys commented Mar 22, 2022

@WikiRik resolving the conflict dismissed your review 😅

@ephys
Copy link
Member Author

ephys commented Mar 22, 2022

Thank you!

@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: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typings for Model.init complains if foreign keys are missing
3 participants