Nodejs Sequelize belongsToMany not working

Viewed 60

I dont know why I am getting this error error: SequelizeDatabaseError: Unknown column 'student-> section ->grademapping.studentId' in 'field list' I just follow this documentation on how to use belongsToMany did i miss something on the documentation? https://sebhastian.com/sequelize-belongstomany/

    let student = await Database.getConnection().models.Student;
    let grademapping = await Database.getConnection().models.Grademapping;
    let section = await Database.getConnection().models.Section;

    let taxtypemapping = await student.findAll({
      attributes:['_id','FirstName','LastName', 'section.Description'],
      include:[
        { model: section, attribute:[] }
      ],
      raw: true
    })

the models

class taxtypedetails extends Sequelize.Model {}
  Section.init(
    {
      _id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      Description: {
        type: Sequelize.STRING,
      },
    },
    { sequelize, tableName: 'section', timestamps: false },
  )

class Student extends Sequelize.Model {}
      Student.init(
        {
          _id: {
            type: Sequelize.INTEGER,
            primaryKey: true,
            autoIncrement: true,
          },
          FirstName: {
            type: Sequelize.STRING,
          },
          LastName: {
            type: Sequelize.STRING,
          },
        },
        { sequelize, tableName: 'student', timestamps: false },
      )

class Grademapping extends Sequelize.Model {}
  Grademapping.init(
    {
      _id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      sectionID: {
        type: Sequelize.INTEGER,
        references: {
          model: 'section',
          key: '_id',
        },
      },
      studentID: {
        type: Sequelize.INTEGER,
        references: {
          model: 'student',
          key: '_id',
        },
      }
    },
    { sequelize, tableName: 'grademapping', timestamps: false },
  )
  student.belongsToMany(section,{through: grademapping})
  section.belongsToMany(student,{through: grademapping})
0 Answers
Related