From c0a0f09f3a942396f2421f38782095adf1e4769c Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Wed, 27 Sep 2017 09:22:06 -0700 Subject: [PATCH] Allow declarative nestRemoting for relations Now relation.options.nestRemoting can be set to true so that nestRemoting will be set up automatically without explicitly calling MyModel.nestRemoting --- lib/model.js | 5 +++++ test/relations.integration.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/model.js b/lib/model.js index a3edb4a1..f9a9173b 100644 --- a/lib/model.js +++ b/lib/model.js @@ -286,6 +286,11 @@ module.exports = function(registry) { relation.type === 'referencesMany') { ModelCtor.hasManyRemoting(relationName, relation, define); } + // Automatically enable nestRemoting if the flag is set to true in the + // relation options + if (relation.options && relation.options.nestRemoting) { + ModelCtor.nestRemoting(relationName); + } } // handle scopes diff --git a/test/relations.integration.js b/test/relations.integration.js index 8b70fc20..3000a395 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -1475,7 +1475,7 @@ describe('relations - integration', function() { ); app.model(Chapter, {dataSource: 'db'}); - Book.hasMany(Page); + Book.hasMany(Page, {options: {nestRemoting: true}}); Book.hasMany(Chapter); Page.hasMany(Note); Chapter.hasMany(Note); @@ -1488,7 +1488,8 @@ describe('relations - integration', function() { Page.remoteMethod('__throw__errors', {isStatic: false, http: {path: '/throws', verb: 'get'}}); - Book.nestRemoting('pages'); + // Now `pages` has nestRemoting set to true and no need to call nestRemoting() + // Book.nestRemoting('pages'); Book.nestRemoting('chapters'); Image.nestRemoting('book');