Fix a regression where undefined id should not match any record

This commit is contained in:
Raymond Feng 2014-07-27 00:38:50 -07:00
parent 074382a448
commit 1a989041ed
1 changed files with 9 additions and 0 deletions

View File

@ -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) {