diff --git a/package.json b/package.json index 9030f0e..57b76a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hapi-sequelize-crud", - "version": "2.0.5", + "version": "2.0.6", "description": "Hapi plugin that automatically generates RESTful API for CRUD", "main": "build/index.js", "config": { diff --git a/src/associations/one-to-many.js b/src/associations/one-to-many.js index c4aff1c..70b8edd 100644 --- a/src/associations/one-to-many.js +++ b/src/associations/one-to-many.js @@ -157,8 +157,11 @@ export const destroy = (server, a, b, names) => { } }); - const method = getMethod(base, names.b, true, 'destroy'); + const method = getMethod(base, names.b, true, 'get'); const list = await method({ where, include }); + await Promise.all(list.map(item => + item.destroy() + )); reply(list); } @@ -183,7 +186,8 @@ export const destroyScope = (server, a, b, names) => { } }); - const method = getMethod(base, names.b, true, 'destroy'); + const method = getMethod(base, names.b, true, 'get'); + const list = await method({ scope: request.params.scope, where, diff --git a/src/associations/one-to-one.js b/src/associations/one-to-one.js index 5702270..eb7f564 100644 --- a/src/associations/one-to-one.js +++ b/src/associations/one-to-one.js @@ -79,9 +79,9 @@ export const destroy = (server, a, b, names) => { } }); - const method = getMethod(base, names.b, false, 'destroy'); - + const method = getMethod(base, names.b, false, 'get'); const instance = await method({ where, include }); + await instance.destroy(); reply(instance); }