Skip to content

Commit

Permalink
Allow declarative nestRemoting for relations
Browse files Browse the repository at this point in the history
Now relation.options.nestRemoting can be set to true so that
nestRemoting will be set up automatically without explicitly
calling MyModel.nestRemoting
  • Loading branch information
Raymond Feng committed Sep 27, 2017
1 parent fcfaf7e commit c0a0f09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/model.js
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/relations.integration.js
Expand Up @@ -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);
Expand All @@ -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');

Expand Down

0 comments on commit c0a0f09

Please sign in to comment.