我们如何使用sequelize在多对多关联表中插入数据

时间:2018-08-04 17:09:23

标签: javascript sql node.js sequelize.js

我如何在评估表中插入与地图表名称中的问题表关联的多个问题,作为我的架构的评估_问题

const assessment=db.define('assessment',{
  id:{type:Sequelize.INTEGER,primaryKey:true,autoIncrement:true},
  name:{type:Sequelize.STRING},
  description:{type:Sequelize.STRING},
  time:{type:Sequelize.DATE},
  prep_time:{type:Sequelize.DATE},
  is_retry:{type:Sequelize.BOOLEAN},
  is_video:{type:Sequelize.BOOLEAN},
  created_at:{type:Sequelize.DATE},
  updated_at:{type:Sequelize.DATE}
},
dbConfig.sequelize_settings
)
const question=db.define('question',{
id:{type:Sequelize.INTEGER,primaryKey:true,autoIncrement:true},
question:{type:Sequelize.STRING},
question_video:{type:Sequelize.STRING},
erpeat_question:{type:Sequelize.STRING},
repeat_question_video:{type:Sequelize.STRING},
created_at:{type:Sequelize.DATE},
updated_at:{type:Sequelize.DATE}
},
dbConfig.sequelize_settings
)
const assessment_question=db.define('assessment_question',{
  id:{type:Sequelize.INTEGER,primaryKey:true,autoIncrement:true},
  question_id:{type:Sequelize.INTEGER},
  assessment_id:{type:Sequelize.INTEGER},
  created_at:{type:Sequelize.DATE},
  updated_at:{type:Sequelize.DATE}
},
dbConfig.sequelize_settings
)

assessment_question.belongsTo(question,{foreignKey:'question_id'})
dimension_question.belongsTo(dimension,{foreignKey:'dimension_id'})

而我的req.body{ name:"something",description:"any description",question:[1,3,4,5]} 问题是question_id的数组。如何创建包含多个问题的单个评估

0 个答案:

没有答案