fix(associate): associating one way is enough

fix(destroy): directly get a `destroy` method instead of find and destroy
This commit is contained in:
Mahdi Dibaiee 2016-03-31 20:40:01 +04:30
parent afb08670e8
commit 544dc23723
4 changed files with 7 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "hapi-sequelize-crud", "name": "hapi-sequelize-crud",
"version": "2.0.4", "version": "2.0.5",
"description": "Hapi plugin that automatically generates RESTful API for CRUD", "description": "Hapi plugin that automatically generates RESTful API for CRUD",
"main": "build/index.js", "main": "build/index.js",
"config": { "config": {

View File

@ -26,13 +26,9 @@ export default (server, a, b, names, options) => {
} }
}); });
const fna = getMethod(instancea, names.b, false, 'add') || const fn = getMethod(instancea, names.b, false, 'add') ||
getMethod(instancea, names.b, false, 'set'); getMethod(instancea, names.b, false, 'set');
const fnb = getMethod(instanceb, names.a, false, 'add') || await fn(instanceb);
getMethod(instanceb, names.a, false, 'set');
fnb(instancea);
fna(instanceb);
reply([instancea, instanceb]); reply([instancea, instanceb]);
} }

View File

@ -157,11 +157,9 @@ export const destroy = (server, a, b, names) => {
} }
}); });
const method = getMethod(base, names.b); const method = getMethod(base, names.b, true, 'destroy');
const list = await method({ where, include }); const list = await method({ where, include });
await* list.map(instance => instance.destroy());
reply(list); reply(list);
} }
}) })
@ -185,7 +183,7 @@ export const destroyScope = (server, a, b, names) => {
} }
}); });
const method = getMethod(base, names.b); const method = getMethod(base, names.b, true, 'destroy');
const list = await method({ const list = await method({
scope: request.params.scope, scope: request.params.scope,
where, where,

View File

@ -79,10 +79,9 @@ export const destroy = (server, a, b, names) => {
} }
}); });
const method = getMethod(base, names.b, false); const method = getMethod(base, names.b, false, 'destroy');
const instance = await method({ where, include }); const instance = await method({ where, include });
await instance.destroy();
reply(instance); reply(instance);
} }