From 1a989041ed21e4090f6aa3e7fb829a21015ca180 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sun, 27 Jul 2014 00:38:50 -0700 Subject: [PATCH 1/2] Fix a regression where undefined id should not match any record --- lib/relation-definition.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 9279fc7e..490d27c2 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -467,6 +467,10 @@ HasMany.prototype.findById = function (fkId, cb) { filter.where[idName] = fkId; filter.where[fk] = modelInstance[pk]; + if (filter.where[fk] === undefined) { + // Foreign key is undefined + return process.nextTick(cb); + } this.definition.applyScope(modelInstance, filter); modelTo.findOne(filter, function (err, inst) { @@ -919,6 +923,11 @@ BelongsTo.prototype.related = function (refresh, params) { var query = {where: {}}; query.where[pk] = modelInstance[fk]; + if (query.where[pk] === undefined) { + // Foreign key is undefined + return process.nextTick(cb); + } + this.definition.applyScope(modelInstance, query); modelTo.findOne(query, function (err, inst) { From 08070aab76406b39bb82425ca149b405b1a635d8 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sun, 27 Jul 2014 00:40:10 -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 797eb50d..30921e06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-datasource-juggler", - "version": "2.1.0", + "version": "2.1.1", "description": "LoopBack DataSoure Juggler", "keywords": [ "StrongLoop",