I am getting the error Type 'typeof Questions' is not assignable to type 'typeof Model'.
while added the relationship in the model.
question.model.ts
import { Column, Table, PrimaryKey, Default, DataType, Model } from "sequelize-typescript";
@Table({timestamps: true})
export class Questions extends Model<Questions> {
@PrimaryKey
@Default(DataType.UUIDV1)
@Column(DataType.UUID)
id: string;
@Column
question: string;
@Column({ defaultValue: true })
isActive: boolean;
}
options.model.ts
import { Column, Table, PrimaryKey, Default, DataType, ForeignKey, HasOne, Model } from "sequelize-typescript";
import { Questions } from "./models/questions.model";
@Table({timestamps: true})
export class Options extends Model<Options> {
@PrimaryKey
@Default(DataType.UUIDV1)
@Column(DataType.UUID)
id: string;
@ForeignKey(() => Questions)
@Column
questionsId: number;
@HasOne(() => Questions)
question: Questions;
@Column({ defaultValue: false })
isCorrectAns: boolean;
}
my user module
import { SequelizeModule } from '@nestjs/sequelize';
import { Questions } from './models/questions.model';
import { Options } from './options.model';
@Module({
imports: [
SequelizeModule.forFeature([Questions, Options])
],
controllers: [UserController],
providers: [UserService]
})
export class UserModule {}
I've had this same issue. Could resolve this by removing the type constructor (<Questions>
, <Options>
).
In my case I had a QuestionsAttributes interface and had to change:
class TalentData extends Model<TalentData, TalentDataAttributes>
to:
class TalentData extends Model implements TalentDataAttributes
But this appears to be a sequelize-typescript error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With