diff --git a/lib/application.js b/lib/application.js index 590c65843..dd3e5f54c 100644 --- a/lib/application.js +++ b/lib/application.js @@ -122,7 +122,7 @@ app.model = function(Model, config) { Model = registry.createModel(modelConfig); // delete config options already applied - ['relations', 'base', 'acls', 'hidden'].forEach(function(prop) { + ['relations', 'base', 'acls', 'methods', 'hidden'].forEach(function(prop) { delete config[prop]; if (config.options) delete config.options[prop]; }); diff --git a/lib/registry.js b/lib/registry.js index f0aa85ce1..52ad2fcb0 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -205,12 +205,24 @@ Registry.prototype.configureModel = function(ModelCtor, config) { 'must be an array of objects', modelName); } + // Remote methods + if (typeof settings.methods === 'object' && settings.methods !== null) { + var methods = settings.methods = settings.methods || {}; + Object.keys(settings.methods).forEach(function(key) { + ModelCtor.remoteMethod(key, settings.methods[key]); + }); + } else if (settings.methods != null) { + console.warn('The methods property of `%s` configuration ' + + 'must be an object', modelName); + } + // Settings var excludedProperties = { base: true, 'super': true, relations: true, acls: true, + methods: true, dataSource: true }; if (typeof config.options === 'object' && config.options !== null) { diff --git a/test/fixtures/simple-integration-app/models.json b/test/fixtures/simple-integration-app/models.json index af1cd5904..c3043f351 100644 --- a/test/fixtures/simple-integration-app/models.json +++ b/test/fixtures/simple-integration-app/models.json @@ -57,6 +57,40 @@ "model": "widget", "type": "hasMany" } + }, + "methods": { + "details": { + "description": "Get additional details about a store.", + "accepts": [{ + "arg": "id", + "type": "any", + "required": true, + "description": "PersistedModel Id" + }], + "returns": { + "arg": "store", + "type": "store", + "root": true + }, + "http": { + "path": "/:id/details", + "verb": "get" + } + }, + "test": { + "description": "Get additional information about a store.", + "isStatic": false, + "accepts": [], + "returns": { + "arg": "store", + "type": "store", + "root": true + }, + "http": { + "path": "/test", + "verb": "get" + } + } } } }, diff --git a/test/remoting.integration.js b/test/remoting.integration.js index 59a553af0..82b5451b5 100644 --- a/test/remoting.integration.js +++ b/test/remoting.integration.js @@ -120,7 +120,9 @@ describe('remoting - integration', function() { 'updateAll(where:object,data:object) POST /stores/update', 'deleteById(id:any) DELETE /stores/:id', 'count(where:object):number GET /stores/count', - 'prototype.updateAttributes(data:object):store PUT /stores/:id' + 'prototype.updateAttributes(data:object):store PUT /stores/:id', + 'details(id:any):store GET /stores/:id/details', + 'prototype.test():store GET /stores/:id/test' ]; // The list of methods is from docs: