续集.js删除查询?
2022-08-30 04:35:51
有没有办法编写删除/删除所有查询,如findAll?
例如,我想做这样的事情(假设MyModel是Sequelize模型...):
MyModel.deleteAll({ where: ['some_field != ?', something] })
.on('success', function() { /* ... */ });
有没有办法编写删除/删除所有查询,如findAll?
例如,我想做这样的事情(假设MyModel是Sequelize模型...):
MyModel.deleteAll({ where: ['some_field != ?', something] })
.on('success', function() { /* ... */ });
我已经深入搜索了代码,一步一步地搜索到以下文件中:
https://github.com/sdepold/sequelize/blob/master/test/Model/destroy.js
https://github.com/sdepold/sequelize/blob/master/lib/model.js#L140
https://github.com/sdepold/sequelize/blob/master/lib/query-interface.js#L207-217
https://github.com/sdepold/sequelize/blob/master/lib/connectors/mysql/query-generator.js
我发现:
没有 deleteAll 方法,有一个可以在记录上调用 destroy() 方法,例如:
Project.find(123).on('success', function(project) {
project.destroy().on('success', function(u) {
if (u && u.deletedAt) {
// successfully deleted the project
}
})
})