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.
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.
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;
You can use destroy method on a model:
Model.destroy({
where: {
id: contentIds
}
});
For more details check the API docs.
cannot truncate a table referenced in a foreign key constraint
, as I ran into on one of my tables. ;)
To destroy all entries in a model:
Model.destroy({
where: {}
}).then(function(){
console.log('destroy all data');
res.redirect('/');
})
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.