From e2ab9ccc931aaa7d2512c054afefe46d1a44eb6b Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 16 Jun 2014 13:46:17 -0700 Subject: [PATCH] Adding back the remoting metadata --- lib/relation-definition.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index ae030143..38c52c93 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -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/// + // 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) {