Javascript Sequelize多对多关系表获得不需要的额外列
我试图在模型Javascript Sequelize多对多关系表获得不需要的额外列,javascript,node.js,entity-relationship,sequelize.js,Javascript,Node.js,Entity Relationship,Sequelize.js,我试图在模型调查和问题之间定义一个m:N关系。关系的名称为SurveyHasQuestions,它也有一个定义(请进一步了解它在关联定义中的用法): 数据库中正确生成了调查和问题的表格(顺便说一句,该表格是Postgres): 及 现在,以下协会: Survey.hasMany(SurveyQuestion, {through: SurveyHasQuestions, foreignKey: 'survey_id'}); SurveyQuestion.hasMany(Survey, {throu
调查
和问题
之间定义一个m:N关系。关系的名称为SurveyHasQuestions
,它也有一个定义(请进一步了解它在关联定义中的用法):
数据库中正确生成了调查
和问题
的表格(顺便说一句,该表格是Postgres):
及
现在,以下协会:
Survey.hasMany(SurveyQuestion, {through: SurveyHasQuestions, foreignKey: 'survey_id'});
SurveyQuestion.hasMany(Survey, {through: SurveyHasQuestions, foreignKey: 'question_id'});
SurveyHasQuestions.belongsTo(Survey, {foreignKey: 'survey_id'});
SurveyHasQuestions.belongsTo(SurveyQuestion, {foreignKey: 'question_id'});
SurveyQuestion.belongsToMany(Survey, {
through: SurveyHasQuestions,
foreignKey: 'question_id'
});
Survey.belongsToMany(SurveyQuestion, {
through: SurveyHasQuestions,
foreignKey: 'survey_id'
});
正确工作,即他们为M:N与所需结构的关系生成一个survey\u has\u questions
表:
shq_id: integer (pkey)
question_id: integer (fkey references survey_question.question_id)
survey_id: integer (fkey references survey.survey_id)
但sequelize发出了警告:使用2xhasmany表示N:M关系已被弃用。请改用belongtomany
因此,为了正确地执行操作,我尝试只使用belongtomany()
。但这些协会:
Survey.hasMany(SurveyQuestion, {through: SurveyHasQuestions, foreignKey: 'survey_id'});
SurveyQuestion.hasMany(Survey, {through: SurveyHasQuestions, foreignKey: 'question_id'});
SurveyHasQuestions.belongsTo(Survey, {foreignKey: 'survey_id'});
SurveyHasQuestions.belongsTo(SurveyQuestion, {foreignKey: 'question_id'});
SurveyQuestion.belongsToMany(Survey, {
through: SurveyHasQuestions,
foreignKey: 'question_id'
});
Survey.belongsToMany(SurveyQuestion, {
through: SurveyHasQuestions,
foreignKey: 'survey_id'
});
为调查生成\u有\u问题
不正确的表格:
shq_id: integer (pkey)
question_id: integer (fkey references survey_question.question_id)
survey_survey_id: integer (fkey references survey.survey_id) <---??? UNWANTED
survey_id: integer (fkey references survey.survey_id)
shq_id:integer(pkey)
问题id:整数(fkey参考调查问题。问题id)
survey_survey_id:integer(fkey references survey.survey_id)这是一个bug:
此后,它已在最新版本中修复,该版本位于v2.0.3:
在此处获取v2.0.3:
shq_id: integer (pkey)
question_id: integer (fkey references survey_question.question_id)
survey_survey_id: integer (fkey references survey.survey_id) <---??? UNWANTED
survey_id: integer (fkey references survey.survey_id)