79083307

Date: 2024-10-13 14:05:11
Score: 1
Natty:
Report link

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

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Huyenlong