Is multiple delete available in sequelize?
node.jssequelize.jsnode.js Problem Overview
I have a multiple contentIds.
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.
node.js Solutions
Solution 1 - node.js
Solution 2 - node.js
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;
Solution 3 - node.js
You can use destroy method on a model:
Model.destroy({
where: {
id: contentIds
}
});
For more details check the API docs.
Solution 4 - node.js
To destroy all entries in a model:
Model.destroy({
where: {}
}).then(function(){
console.log('destroy all data');
res.redirect('/');
})
Solution 5 - node.js
Note that if you have paranoid enabled, and you really want to destroy the rows from the table instead of just setting their deleted_at
timestamp, pass the option force: true
to the Model.destroy({})
method.