node.js sequelize 中是否可以进行多次删除?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23929098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is multiple delete available in sequelize?
提问by Anuj
I have a multiple contentIds.
我有多个 contentId。
Mode.findAll({
where: {
id: contentIds
}
})
After finding all how can I Delete multiple rows from a table.
在找到所有如何从表中删除多行之后。
Or tell me other options to delete multiple records with a single query.
或者告诉我使用单个查询删除多个记录的其他选项。
回答by Sergey Karasev
回答by Mardari
If you want to delete ALL models of a specific type, you can use:
如果要删除特定类型的所有模型,可以使用:
Model.destroy({where: {}}).then(function () {});
This will delete all records of type 'Model' from database. Tested with mysql;
这将从数据库中删除所有类型为“模型”的记录。用mysql测试;
回答by Nikolay Lukyanchuk
Use destroy method http://sequelize.readthedocs.org/en/latest/docs/instances/#destroying-deleting-persistent-instances
使用销毁方法http://sequelize.readthedocs.org/en/latest/docs/instances/#destroying-deleting-persistent-instances
Mode.destroy({
where: {
id: contentIds
}
})
回答by Juan Navarrete
To destroy all entries in a model:
要销毁模型中的所有条目:
Model.destroy({
where: {}
}).then(function(){
console.log('destroy all data');
res.redirect('/');
})

