Update model.js

*Add doc comments for nestRemoting
*change cb to filterCallback in nestRemoting
This commit is contained in:
Rand McKinney 2015-12-01 14:37:25 -08:00 committed by Amir Jafarian
parent bfd5059d11
commit 17abd8ac76
1 changed files with 19 additions and 4 deletions

View File

@ -660,9 +660,24 @@ module.exports = function(registry) {
};
Model.nestRemoting = function(relationName, options, cb) {
if (typeof options === 'function' && !cb) {
cb = options;
/**
* Enabled deeply-nested queries of related models via REST API.
*
* @param {String} relationName Name of the nested relation.
* @options {Object} [options] It is optional. See below.
* @param {String} pathName The HTTP path (relative to the model) at which your remote method is exposed.
* @param {String} filterMethod The filter name.
* @param {String} paramName The argument name that the remote method accepts.
* @param {String} getterName The getter name.
* @param {Boolean} hooks Whether to inherit before/after hooks.
* @callback {Function} filterCallback The Optional filter function.
* @param {Object} SharedMethod object. See [here](https://apidocs.strongloop.com/strong-remoting/#sharedmethod).
* @param {Object} RelationDefinition object which includes relation `type`, `ModelConstructor` of `modelFrom`, `modelTo`, `keyFrom`, `keyTo` and more relation definitions.
*/
Model.nestRemoting = function(relationName, options, filterCallback) {
if (typeof options === 'function' && !filterCallback) {
filterCallback = options;
options = {};
}
options = options || {};
@ -702,7 +717,7 @@ module.exports = function(registry) {
// 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 = cb || options.filterMethod || function(method, relation) {
var filter = filterCallback || options.filterMethod || function(method, relation) {
var matches = method.name.match(regExp);
if (matches) {
return '__' + matches[1] + '__' + relation.name + '__' + matches[2];