Sequelize association error
Unanswered
Huyenlong posted this in #help-forum
Hi and happy new year
I have an error with association in sequelize V7 :
This is the code:
I do not understand where is my mistake.
Thanks for help and sorry for my English
I have an error with association in sequelize V7 :
AssociationError [SequelizeAssociationError]: Defining HasMany association "club" from Comitee to Club failed
[cause]: AssociationError [SequelizeAssociationError]: Association "club" needs to create the BelongsTo association "comitee" from Club to Comitee, but it failed
[cause]: Error: Invalid input received, got Comitee, expected a Model Class, a TableNameWithSchema object, or a table name string
at PostgresQueryGenerator.extractTableDetails
This is the code:
import { Club } from './Club';
export class Comitee extends Model<InferAttributes<Comitee>, InferCreationAttributes<Comitee>> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>
@HasMany(() => Club, 'comiteeId')
declare club?: NonAttribute<Club[]>
declare getClubs: HasManyGetAssociationsMixin<Club>
}
import { Comitee } from './Comitee'
export class Club extends Model<InferAttributes<Club>, InferCreationAttributes<Club>> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>
@BelongsTo(() => Comitee, 'comiteeId')
@Attribute(DataTypes.INTEGER)
@NotNull
declare comiteeId: number | null
declare comitee?: NonAttribute<Comitee>;
}
I do not understand where is my mistake.
Thanks for help and sorry for my English