我想知道是否可以使用 Loopback.js 中的单个 API 请求一次修补或删除多个模型实例。我认为我可以通过包含要更新的模型实例数组的调用来做到这一点,但显然这不起作用。
最佳答案
使用这些持久模型方法:
<强>1。全部更新
PersistedModel.updateAll([where], data, callback)
More info, check the official documentation
PersistedModel.updateAll({
field1: value1,
field2: value2,
},
data,
function (err, info) {
if (err) { console.log(err); }
console.log(info, info.count); // shows number of udaptes
})
<强>2。全部销毁
PersistedModel.destroyAll([where], callback)
More info, check the official documentation
PersistedModel.destoryAll({
field1: value1,
field2: value2,
},
data,
function (err, info) {
if (err) { console.log(err); }
console.log(info, info.count); // shows number of items deleted
})
关于javascript - 有没有办法通过一次调用来更新或删除多个模型实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47536987/