Enable Destroy All API for a model in Loopback
Destroy All API (Model.destroyAll()
) is, by default, disabled to avoid accidental bulk deletion of data. However, it might be required for developmental purposes.
Remote Method⌗
A corresponding remote method can be added to the model.js
file to enable this API. This method also supports a filter to enable selective deletion.
module.exports = function (Model) {
Model.remoteMethod('destroyAll', {
isStatic: true,
description: 'Delete all matching records',
accessType: 'WRITE',
accepts: { arg: 'where', type: 'object', description: 'filter.where object' },
http: { verb: 'del', path: '/' }
});
};
Read other posts
Discuss Post