我可以使用 build 和 include 将相关模型全部插入一个,但无法在一次调用中更新:(
我要更新的示例数据
{
“身份证”:9,
"name": "Cleansheet Type8",
"description": "Cleansheet Type1 的描述",
"createdBy": 1,
“租户 ID”:空,
“部分”:[
{
“身份证”:6,
"name": "section8",
"CleansheetTypeId": 19,
“变量”:[
{
“身份证”:2,
"name": "variable8",
“类型”:“字符串”,
“defaultFlag”:真,
"defaultVal": "someVal",
“requiredFlag”:真,
"comment": "一些评论",
}
]
}
]
}
最佳答案
在 Sequelize
中,无法更新相关模型。您必须将查询分为两个步骤并使用 create 和 bulkCreate 的组合。它看起来像这样 -
User.findOrCreate(req.body.user).then(function(user){
return Follow.bulkCreate([record1, record2, record3]);
});
关于node.js - 如何在一次调用中使用 Sequelize 更新关联模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35385581/