sequelize-typescript
sequelize-typescript copied to clipboard
Polymorphic association
Issue
Can we define polymorphic association?
Versions
- "sequelize": "^6.6.5",
- "sequelize-typescript": "^2.1.0",
- "typescript": "^4.3.5"
Issue type
- [ ] bug report
- [x ] feature request
Actual behavior
I can't find any documentation related to polymorphism association
Expected behavior
The original sequelize support polymorphism association but I can't find a way using this package
@archansel Hi, did you find any example? I also trying to find one.
Nope I end up doing it manually to get the result I want
column name: contextId and contextType
@BelongsTo(() => Model1, 'contextId')
model1: Model1;
@BelongsTo(() => Model2, 'contextId')
model2: Model2;
@Column(DataType.VIRTUAL)
get title(): string {
switch (this.contextType) {
case Model1.name:
return this.model1.title;
case Model2.name:
return this.model2.name;
default:
return null;
}
}
Bump.