I modifie a little the code :
import { Sequelize,Model, InferAttributes, InferCreationAttributes, NonAttribute,CreationOptional, DataTypes, HasManyGetAssociationsMixin} from '@sequelize/core'
import { Attribute, PrimaryKey, AutoIncrement, NotNull, BelongsTo, BelongsToMany, HasOne, HasMany } from '@sequelize/core/decorators-legacy'
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 clubs?: NonAttribute<Club[]>
declare getClubs: HasManyGetAssociationsMixin<Club>
}
export const GET = async (req: NextRequest, res: NextResponse ) => {
const comitee = await Comitee.findByPk(1)
if (!comitee) return NextResponse.json(" pas de comité trouvée")
console.log("comitee", comitee)
// this return the good value
console.log("comitee get clubs", await comitee.getClubs())
// this retun getClubs() is not a function
}
}
But still the same error.
I do not understand. I make a good link beetween the table and with the "getClubs" in model the type
declare getClubs: HasManyGetAssociationsMixin<Club>
The type say it is a function
What i did bad ?
Sorry to my english and thanks