Cardoso
Cardoso

Reputation: 1088

TypeError: existExecution.addGroup is not a function

I am integrating ORM with sequelize to the express project. The database is MySQL DB.
I have some problems in integrating many to many relationships.
Here are two models that I am going to integrate many to many relationships.

export default (sequelize, Sequelize) => {
  const Execution = sequelize.define('execution', {
    id: {
      type: Sequelize.INTEGER,
      autoIncrement: true,
      primaryKey: true
    },
    group_by: {
      type: Sequelize.STRING
    },
    group_order: {
      type: Sequelize.STRING
    },
    sort_by: {
      type: Sequelize.STRING
    },
    sort_order: {
      type: Sequelize.STRING
    }
  }, {
    timestamps: false
  })

  return Execution
}
export default (sequelize, Sequelize) => {
  const ExecutionGroup = sequelize.define('Group', {
    id: {
      type: Sequelize.STRING,
      primaryKey: true
    },
    title: {
      type: Sequelize.STRING
    },
    order: {
      type: Sequelize.STRING
    }
  }, {
    timestamps: false,
    tableName: 'execution_group'
  })

  return ExecutionGroup
}

And this is the relationship model.

export default (sequelize, Sequelize) => {
  const ExecutionGroupRelation = sequelize.define('execution_group_relation', {}, {
    timestamps: false
  })

  return ExecutionGroupRelation
}

Here is my code for integrating many to many relationships.

Group.belongsToMany(Execution, {
    through: ExecutionGroupRelation,
  })

I am trying to call addGroup function, but it says it isn't declared. Now, how can I add groups to the execution? I can share more detail about what you want.

Let me share the reference document I followed. https://www.bezkoder.com/sequelize-associate-many-to-many/#Sequelize_Many-to-Many_example_Overview

From this document, I can't find out the TagController.addTutorial function's code.

TagController.addTutorial(tag1.id, tut1.id);

This code showing addTutorial is not defined error. How can I solve this problem?

Upvotes: 1

Views: 63

Answers (1)

Anatoly
Anatoly

Reputation: 22803

To find out how to fix addGroup issue and find the definition of addTutorial just following the tuturial and use the whole code from there and look at addTutorial function definition in TagController

Upvotes: 1

Related Questions