fix(destroy): associative remove methods require the instance, they don't accept queries, so fallback to manual destroy

This commit is contained in:
Mahdi Dibaiee 2016-04-19 11:39:59 +04:30
parent 544dc23723
commit 973f63640c
3 changed files with 9 additions and 5 deletions

View File

@ -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": {

View File

@ -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,

View File

@ -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);
}