This fixes the apparent scope and comparison issues when calling a foreign key relation.
This commit is contained in:
parent
cdd328c902
commit
cba174b4ff
|
@ -946,7 +946,7 @@ AbstractClass.belongsTo = function (anotherClass, params) {
|
||||||
anotherClass.find(id, function (err,inst) {
|
anotherClass.find(id, function (err,inst) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (!inst) return cb(null, null);
|
if (!inst) return cb(null, null);
|
||||||
if (inst[fk] === this.id) {
|
if (inst.id === this[fk]) {
|
||||||
cb(null, inst);
|
cb(null, inst);
|
||||||
} else {
|
} else {
|
||||||
cb(new Error('Permission denied'));
|
cb(new Error('Permission denied'));
|
||||||
|
@ -971,12 +971,12 @@ AbstractClass.belongsTo = function (anotherClass, params) {
|
||||||
this.__cachedRelations[methodName] = p;
|
this.__cachedRelations[methodName] = p;
|
||||||
} else if (typeof p === 'function') { // acts as async getter
|
} else if (typeof p === 'function') { // acts as async getter
|
||||||
if (typeof cachedValue === 'undefined') {
|
if (typeof cachedValue === 'undefined') {
|
||||||
this.__finders__[methodName](this[fk], function(err, inst) {
|
this.__finders__[methodName].apply(self, [this[fk], function(err, inst) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
self.__cachedRelations[methodName] = inst;
|
self.__cachedRelations[methodName] = inst;
|
||||||
}
|
}
|
||||||
p(err, inst);
|
p(err, inst);
|
||||||
});
|
}]);
|
||||||
return this[fk];
|
return this[fk];
|
||||||
} else {
|
} else {
|
||||||
p(null, cachedValue);
|
p(null, cachedValue);
|
||||||
|
|
Loading…
Reference in New Issue