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 association decorators #15483

Merged
merged 4 commits into from Dec 20, 2022
Merged

feat: add association decorators #15483

merged 4 commits into from Dec 20, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Dec 19, 2022

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • 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?
  • Does the name of your PR follow our conventions?

Description Of Change

This is part of #15334

This PR adds decorators @BelongsTo, @HasMany, @HasOne, and @BelongsToMany.

Their signature is not identical to the one from sequelize-typescript:

  • The @ForeignKey decorator was only ever used as a way for the above 4 decorators to guess which attribute was the foreign key. From experience, this ended up being more confusing than helpful. I have not included it in my implementation. Instead, users are required to specify the foreignKey parameter in @BelongsTo, @HasMany, @HasOne, and @BelongsToMany.
  • Type is stricter for @BelongsTo, @HasMany, and @HasOne: All of them check that the foreign key has been defined (in type) on the proper model
  • All signatures of @BelongsToMany have been dropped except one. They were all too difficult to read. The only remaining signature is @BelongsToMany(target, options)
  • Pass models object in association annotations sequelize-typescript#1206 has been implemented in this PR

This is the last PR that was really essential to make the decorator system usable. The remaining 5 decorators are shortcuts

WikiRik
WikiRik previously approved these changes Dec 20, 2022
src/decorators/legacy/associations.ts Outdated Show resolved Hide resolved
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
@ephys ephys merged commit 3770827 into main Dec 20, 2022
@ephys ephys deleted the ephys/association-decorators branch December 20, 2022 12:40
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.

None yet

2 participants