在 Sequelize 中使用 bulkDestroy
use bulkDestroy in Sequelize
我想知道如何删除数组中的所有值,我的数组包含如下 ID:[1,2,3,4]
,我试过:
models.products
.destroy({where: {req.body.ids}})
.then(function(data){ res.json(data) })
但是我得到了 data
undefined,没有任何内容被删除...
您的条件中缺少 id
。
Model.destroy({ where: { id: [1,2,3,4] }})
只是添加到 +Adam 的回复中:
对于数组,您需要添加一个 $in: 子句。
Models.products
.destroy({where: {$in: req.body.ids}})
...
我想知道如何删除数组中的所有值,我的数组包含如下 ID:[1,2,3,4]
,我试过:
models.products
.destroy({where: {req.body.ids}})
.then(function(data){ res.json(data) })
但是我得到了 data
undefined,没有任何内容被删除...
您的条件中缺少 id
。
Model.destroy({ where: { id: [1,2,3,4] }})
只是添加到 +Adam 的回复中:
对于数组,您需要添加一个 $in: 子句。
Models.products
.destroy({where: {$in: req.body.ids}})
...