fix(associate): associating one way is enough
fix(destroy): directly get a `destroy` method instead of find and destroy
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "hapi-sequelize-crud", | ||||
|   "version": "2.0.4", | ||||
|   "version": "2.0.5", | ||||
|   "description": "Hapi plugin that automatically generates RESTful API for CRUD", | ||||
|   "main": "build/index.js", | ||||
|   "config": { | ||||
|   | ||||
| @@ -26,13 +26,9 @@ export default (server, a, b, names, options) => { | ||||
|         } | ||||
|       }); | ||||
|  | ||||
|       const fna = getMethod(instancea, names.b, false, 'add') || | ||||
|                   getMethod(instancea, names.b, false, 'set'); | ||||
|       const fnb = getMethod(instanceb, names.a, false, 'add') || | ||||
|                   getMethod(instanceb, names.a, false, 'set'); | ||||
|  | ||||
|       fnb(instancea); | ||||
|       fna(instanceb); | ||||
|       const fn = getMethod(instancea, names.b, false, 'add') || | ||||
|                  getMethod(instancea, names.b, false, 'set'); | ||||
|       await fn(instanceb); | ||||
|  | ||||
|       reply([instancea, instanceb]); | ||||
|     } | ||||
|   | ||||
| @@ -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 }); | ||||
|  | ||||
|       await* list.map(instance => instance.destroy()); | ||||
|  | ||||
|       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({ | ||||
|         scope: request.params.scope, | ||||
|         where, | ||||
|   | ||||
| @@ -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 }); | ||||
|       await instance.destroy(); | ||||
|  | ||||
|       reply(instance); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user