Jonathan Solorzano
Jonathan Solorzano

Reputation: 7032

use bulkDestroy in Sequelize

I'd like to know how to delete all values in an array, my array contains the ids like: [1,2,3,4], I've tried:

models.products
.destroy({where: {req.body.ids}})
.then(function(data){ res.json(data) })

But I got data undefined, and nothing is deleted...

Upvotes: 3

Views: 2745

Answers (2)

Ben Polge
Ben Polge

Reputation: 646

Just to add to +Adam's response:

for arrays you'll need to add an $in: clause.

Models.products
 .destroy({where: {$in: req.body.ids}})
 ...

Upvotes: 2

Adam
Adam

Reputation: 5253

You've missed the id from your criteria.

Model.destroy({ where: { id: [1,2,3,4] }})

Upvotes: 8

Related Questions