无法在Sequelize中的两个模型之间创建关联,因为关联不是通过Sequelize.Model的子类调用的

时间:2019-04-14 03:23:57

标签: javascript sequelize.js

我正在为我的项目使用Sequelize v5.0,我有两个定义如下的模型:

  • user.js包括用户模型
//USER MODEL in user.js
const Sequelize = require("sequelize");
const db = require("../config/database");
const Conversation = require("./conversation");
const Participation = require("./participation");

const User = db.define("users", {
    //...attributes
});

User.belongsToMany(Conversation, { through: Participation });

module.exports = User;
  • conversation.js包括会话模型
const Sequelize = require("sequelize");
const db = require("../config/database");
const User = require("./user");
const Participation = require("./participation");

const Conversation = db.define("conversations", {
    //...attributes
});

Conversation.belongsToMany(User, { through: Participation });

module.exports = Conversation;

当我运行项目时,它会引发以下错误:

Error: conversations.belongsToMany called with something that's not a subclass of Sequelize.Model
    at Function.belongsToMany (/home/phandungtri/Projects/CodeChat/node_modules/sequelize/lib/associations/mixin.js:49:13)
    at Object.<anonymous> (/home/phandungtri/Projects/CodeChat/models/conversation.js:22:14)
    ...

conversations.belongsToMany调用了什么不是Sequelize.Model的子类是什么意思?

0 个答案:

没有答案