Skip to content

Integrate extends Model into @Table decorator #1744

Open
@liv1n9

Description

@liv1n9

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions