问题
By default in Loopback delete all matching instances is not exposed over REST API. How to enable it?
回答1:
I couldn't find any reference to the documentation, but I successfully tested this.
TLDR:
Put in this in your model.js
or in server.js
app.models.<model>.remoteMethod('destroyAll', {
description: 'Delete all matching records.',
accessType: 'WRITE',
accepts: [
{arg: 'where', type: 'object', description: 'filter.where object'},
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
],
returns: {
arg: 'count',
type: 'object',
description: 'The number of instances deleted',
root: true,
},
http: {verb: 'del', path: '/'},
// shared: false,
});
The above is simply the remote method declaration from the source, except the shared: false
is commented out.
来源:https://stackoverflow.com/questions/49858943/loopbackjs-3-x-how-to-enable-delete-all-matching-instances