sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Integrate extends Model into @Table decorator

Open liv1n9 opened this issue 8 months ago • 0 comments

I'm using sequelize-typescript in my project. To define a model, I create two separate classes: an entity class and a model class:

// Entity class
class User {
  username: string;
  fullName: string;
}

// Model class
@Table({ tableName: "user" })
class UserModel extends Model implements User {
  @Column
  username: string;
  
  @Column
  fullName: string;
}

I do this in order to separate my entitiy's interfaces from sequelize model's interface (using in repository pattern). It's a bit inconvinient since I have to do the declaring job twice.

So can we integrate extends Model to @Table decorator? So that I only have to define everything in Entity classes. For example:

@Table({ tableName: "user", extends: false })
class User {
  @Column
  username: string;
  
  @Column
  fullName: string;
}

liv1n9 avatar Apr 11 '25 08:04 liv1n9