Skip to content

Allow model generics in Table decorator #901

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

Merged
merged 1 commit into from
Feb 13, 2021
Merged

Allow model generics in Table decorator #901

merged 1 commit into from
Feb 13, 2021

Conversation

KapitanOczywisty
Copy link
Contributor

This PR helps when writing @Table definitions with hooks or other model-dependent options. I'm ignoring other decorators like @Column since these don't have any use from model.

I can use some help with updating docs, since I'm not a native speaker nor have any idea what I'm doing

@Table<Post>({
  hooks: {
    beforeUpdate: (instance) => {
      // this will result in error before PR
      instance.random = 4;
    },
  },
})
export class Post extends Model {
  @Column(DataType.INTEGER)
  random: number;
}

// alternative which works even now
@Table({
  hooks: {
    beforeUpdate: (instance: Post) => {
      // this works ok
      instance.random = 4;
    },
  },
})

@codecov
Copy link

codecov bot commented Feb 7, 2021

Codecov Report

Merging #901 (b53c588) into master (3ba9667) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #901   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files         117      117           
  Lines        1126     1126           
  Branches      129      129           
=======================================
  Hits         1072     1072           
  Misses         22       22           
  Partials       32       32           
Impacted Files Coverage Δ
src/model/table/table.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ba9667...b53c588. Read the comment docs.

@lukashroch lukashroch merged commit 6547ffd into sequelize:master Feb 13, 2021
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