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);