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

Possibility to extend one model entity from another

Open EgoBrainProgrammer opened this issue 4 years ago • 2 comments

Issue

Versions

  • sequelize: ^6.5.0
  • sequelize-typescript: ^2.1.0
  • typescript: ^4.0.5

Issue type

  • [ ] bug report
  • [x] feature request

Actual behavior

Expected behavior

I need feature extending one Model from another. For purpose to avoid repetitions of entity basic attributes. See related code.

Steps to reproduce

Related code

// Base Entity
export class BaseEntity {
    @Column()
    fieldOne: number;

    @Column()
    fieldTwo: string;
}

// Child entity with three fields
export class Provider extends Model<BaseEntity, ProviderCreationAttrs> {    
    @Column({
        type: DataType.STRING,
        unique: true,
        allowNull: false,
    })
    fieldThree: boolean;
}

EgoBrainProgrammer avatar Apr 30 '21 01:04 EgoBrainProgrammer

Having the exact same requirement and i'm also using sequelize and sequelize-typescript

schealex avatar Jul 21 '21 22:07 schealex

This is something we plan on improving in Sequelize itself (See 'Model Inheritance' here https://github.com/sequelize/sequelize/issues/14298)

ephys avatar Apr 07 '22 13:04 ephys