Fix a regression where undefined id should not match any record
This commit is contained in:
parent
074382a448
commit
1a989041ed
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue