From 0e6bba4ded0fbe4aa650adeaad783a4948468c16 Mon Sep 17 00:00:00 2001 From: Clark Wang Date: Mon, 1 Sep 2014 13:52:14 +0800 Subject: [PATCH] Restrict that only hasManyThrough can have additional properties Signed-off-by: Clark Wang --- lib/models/model.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/models/model.js b/lib/models/model.js index 0df6638d..3e7a30c6 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -426,17 +426,19 @@ Model.hasManyRemoting = function (relationName, relation, define) { if (relation.modelThrough || relation.type === 'referencesMany') { var modelThrough = relation.modelThrough || relation.modelTo; - + + var accepts = []; + if (relation.type === 'hasMany' && relation.modelThrough) { + accepts.push({arg: 'data', type: modelThrough.modelName, http: {source: 'body'}}); + } + var addFunc = this.prototype['__link__' + relationName]; define('__link__' + relationName, { isStatic: false, http: {verb: 'put', path: '/' + pathName + '/rel/:fk'}, - accepts: [ - {arg: 'fk', type: 'any', + accepts: [{arg: 'fk', type: 'any', description: 'Foreign key for ' + relationName, required: true, - http: {source: 'path'}}, - {arg: 'data', type: modelThrough.modelName, http: {source: 'body'}} - ], + http: {source: 'path'}}].concat(accepts), description: 'Add a related item by id for ' + relationName, returns: {arg: relationName, type: modelThrough.modelName, root: true} }, addFunc);