Sequelize-如何在多对多关联中设置外键名称

时间:2019-03-07 02:43:49

标签: javascript node.js postgresql ecmascript-6 sequelize.js

我正在使用Sequelize创建数据库模式。而且我找不到如何在多对多关系中设置外键名称。

我有一个 investment_manager

const Investment_manager = sequelize.define('investment_manager', {
    im_id : {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
    im_name : {type: Sequelize.STRING, allowNull: false}
    // Other fields ....
});

项目

const Project = sequelize.define('project', {
    project_id : {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
    project_name : {type: Sequelize.STRING, allowNull: false},
    // Other fields ....
});

asso_project_im

const Asso_project_im = sequelize.define('asso_project_im', {
    asso_id: {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
    // Other fields ....
});

我使用 belongsToMany

连接表
investment_manager.belongsToMany(project, {as: 'im', through: 'asso_project_im', foreign_key: 'im_id'});
project.belongsToMany(investment_manager, {as: 'project', through: 'asso_project_im', foreign_key: 'project_id'});

我想在名为'im_id''project_id'的Asso_project_im表中创建外键,有什么办法吗?非常感谢!

0 个答案:

没有答案