Adding back the remoting metadata

This commit is contained in:
Raymond Feng 2014-06-16 13:46:17 -07:00
parent 046816191d
commit e2ab9ccc93
1 changed files with 19 additions and 1 deletions

View File

@ -520,12 +520,30 @@ RelationDefinition.belongsTo = function (modelFrom, modelTo, params) {
configurable: true,
get: function() {
var relation = new BelongsTo(relationDef, this);
var relationMethod = relation.related.bind(relation)
var relationMethod = relation.related.bind(relation);
relationMethod.create = relation.create.bind(relation);
relationMethod.build = relation.build.bind(relation);
relationMethod._targetClass = relationDef.modelTo.modelName;
return relationMethod;
}
});
// Wrap the property into a function for remoting
// so that it can be accessed as /api/<model>/<id>/<belongsToRelationName>
// For example, /api/orders/1/customer
var fn = function() {
var f = this[relationName];
f.apply(this, arguments);
};
fn.shared = true;
fn.http = {verb: 'get', path: '/' + relationName};
fn.accepts = {arg: 'refresh', type: 'boolean', http: {source: 'query'}};
fn.description = 'Fetches belongsTo relation ' + relationName;
fn.returns = {arg: relationName, type: 'object', root: true};
modelFrom.prototype['__get__' + relationName] = fn;
};
BelongsTo.prototype.create = function(targetModelData, cb) {