From 68d26962480b735ae535fb2c38735bdf59ab6888 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 3 Apr 2014 20:41:53 -0700 Subject: [PATCH 1/2] Fix the method for belongsTo with correct receiver --- lib/include.js | 5 ++--- lib/relations.js | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/include.js b/lib/include.js index e044f062..4060e55e 100644 --- a/lib/include.js +++ b/lib/include.js @@ -119,9 +119,8 @@ Inclusion.include = function (objects, include, cb) { } } var inst = (obj instanceof self) ? obj : new self(obj); - var relationMethod = inst[relationName]; - // FIXME: [rfeng] How do we pass in the refresh flag? - relationMethod(function (err, result) { + // Calling the relation method on the instance + inst[relationName](function (err, result) { if (err) { return callback(err); } else { diff --git a/lib/relations.js b/lib/relations.js index 3b4a05a7..37ec06a9 100644 --- a/lib/relations.js +++ b/lib/relations.js @@ -340,10 +340,13 @@ Relation.belongsTo = function (anotherClass, params) { // Define a property for the scope so that we have 'this' for the scoped methods Object.defineProperty(this.prototype, methodName, { - enumerable: false, + enumerable: true, configurable: true, get: function () { - var fn = relationMethod.bind(this); + var fn = function() { + // Call the relation method on the declaring model instance + return relationMethod.apply(this, arguments); + } // Set the remoting metadata so that it can be accessed as /api/// // For example, /api/orders/1/customer fn.shared = true; From e3eca4cf19a26838270341f4d55db3e55c31beb7 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 4 Apr 2014 09:02:12 -0700 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36a37987..770e26c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-datasource-juggler", - "version": "1.3.9", + "version": "1.3.10", "description": "LoopBack DataSoure Juggler", "keywords": [ "StrongLoop",