From cc0d376cc31a5cc777299af98fb55906abeaebe9 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Mon, 4 Aug 2014 19:08:43 +0200 Subject: [PATCH] filterMethod can also be a direct callback --- lib/models/model.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/models/model.js b/lib/models/model.js index 3c9a21c9..73ab8737 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -473,9 +473,14 @@ Model.scopeRemoting = function(relationName, relation, define) { }); }; -Model.nestRemoting = function(relationName, options) { - var regExp = /^__([^_]+)__([^_]+)$/; +Model.nestRemoting = function(relationName, options, cb) { + if (typeof options === 'function' && !cb) { + cb = options; + options = {}; + } options = options || {}; + + var regExp = /^__([^_]+)__([^_]+)$/; var relation = this.relations[relationName]; if (relation && relation.modelTo && relation.modelTo.sharedClass) { var self = this; @@ -504,7 +509,7 @@ Model.nestRemoting = function(relationName, options) { // A method should return the method name to use, if it is to be // included as a nested method - a falsy return value will skip. - var filter = options.filterMethod || function(method, relation) { + var filter = cb || options.filterMethod || function(method, relation) { var matches = method.name.match(regExp); if (matches) { return '__' + matches[1] + '__' + relation.name + '__' + matches[2];