From a6590a965099781d2ad4dc1cd8c74957592adcab Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sat, 4 Feb 2017 22:17:34 +0330 Subject: [PATCH] fix(crud): see 83eadf0929a2506541e34b4a6f73d46bfa2404d3 and #37 --- package.json | 2 +- src/index.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3bd8434..801d1ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hapi-sequelize-crud", - "version": "2.9.2", + "version": "2.9.3", "description": "Hapi plugin that automatically generates RESTful API for CRUD", "main": "build/index.js", "config": { diff --git a/src/index.js b/src/index.js index 2df0313..cafa96d 100644 --- a/src/index.js +++ b/src/index.js @@ -37,7 +37,6 @@ const register = (server, options = {}, next) => { // Join tables if (model.options.name.singular !== model.name) continue; - crud(server, model, options); for (const key of Object.keys(model.associations)) { const association = model.associations[key]; @@ -93,6 +92,17 @@ const register = (server, options = {}, next) => { } } + // build the methods for each model now that we've defined all the + // associations + Object.keys(models).filter((modelName) => { + const model = models[modelName]; + return model.options.name.singular === model.name; + }).forEach((modelName) => { + const model = models[modelName]; + crud(server, model, options); + }); + + next(); };