diff --git a/lib/models/model.js b/lib/models/model.js index 8e018a34..3c9a21c9 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -502,9 +502,18 @@ Model.nestRemoting = function(relationName, options) { var acceptArgs = []; } + // 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 matches = method.name.match(regExp); + if (matches) { + return '__' + matches[1] + '__' + relation.name + '__' + matches[2]; + } + }; + sharedToClass.methods().forEach(function(method) { - var matches; - if (!method.isStatic && (matches = method.name.match(regExp))) { + var methodName; + if (!method.isStatic && (methodName = filter(method, relation))) { var prefix = relation.multiple ? '__findById__' : '__get__'; var getterName = options.getterName || (prefix + relationName); @@ -519,7 +528,6 @@ Model.nestRemoting = function(relationName, options) { } var opts = {}; - var methodName = '__' + matches[1] + '__' + relationName + '__' + matches[2]; opts.accepts = acceptArgs.concat(method.accepts || []); opts.returns = [].concat(method.returns || []);