不需要自动生成sequelize的id属性

时间:2017-03-17 07:57:35

标签: database sequelize.js

set @SQL= '
select 
    pushto as MSISDN,
    pushprice as Price,
    pushdate as DateTime,
    pushtext as Message 
    from '+@tblname+' 
    WITH (NOLOCK) 
    INNER JOIN INAPremium..INA_Keyword K on R.keyid = K.keyid 
    WHERE '+@sqldate+ @scodelist+ @clientlist + @piclist + @DNType + @pkeywordlist + @seckeywordlist +' 
    order by pushdate desc'

我不需要此表中的let data = require('./../../config/db') let connection = data.connection let sequelize = data.sequelize let sql = function(){ let clubMembers = connection.define('club_members',{ position:{ type :sequelize.ENUM('President','Treasurer') , allowNull : false } }, { classMethods : { associate : function(models){ let clubMembers = models.club_members let club = models.club let student = models.student club.hasMany(clubMembers,{ foreignKey : "club_id" }) student.hasMany(clubMembers,{ foreignKey : "student_id" }) } } } ); return clubMembers; } module.exports = sql; 属性,但是sequelize会自动创建它。并且两个外键的组合应被视为主键,即复合主键。 enter image description here

1 个答案:

答案 0 :(得分:1)

您应该在associate功能

中使用belongsToMany
associate: function(models){
    models.club.belongsToMany(models.student, { through: models.club_members, foreignKey: 'club_id' });
    models.student.belongsToMany(models.club, { through: models.club_members, foreignKey: 'student_id' });
}

这将创建club_members表,其中包含由club_idstudent_id组成的复合主键,而不包含默认的id列。