From cba174b4ff3be23be9b32fcfc71fa3ed821cdb51 Mon Sep 17 00:00:00 2001 From: dgsan <-> Date: Fri, 1 Feb 2013 10:15:03 -0700 Subject: [PATCH] This fixes the apparent scope and comparison issues when calling a foreign key relation. --- lib/abstract-class.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 2b9c63df..cb119b68 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -946,7 +946,7 @@ AbstractClass.belongsTo = function (anotherClass, params) { anotherClass.find(id, function (err,inst) { if (err) return cb(err); if (!inst) return cb(null, null); - if (inst[fk] === this.id) { + if (inst.id === this[fk]) { cb(null, inst); } else { cb(new Error('Permission denied')); @@ -971,12 +971,12 @@ AbstractClass.belongsTo = function (anotherClass, params) { this.__cachedRelations[methodName] = p; } else if (typeof p === 'function') { // acts as async getter if (typeof cachedValue === 'undefined') { - this.__finders__[methodName](this[fk], function(err, inst) { + this.__finders__[methodName].apply(self, [this[fk], function(err, inst) { if (!err) { self.__cachedRelations[methodName] = inst; } p(err, inst); - }); + }]); return this[fk]; } else { p(null, cachedValue);