Allow 0 as the FK
See https://github.com/strongloop/loopback/issues/967
This commit is contained in:
parent
c0fa60b42c
commit
3ee3ba3dcf
|
@ -783,7 +783,7 @@ HasMany.prototype.findById = function (fkId, options, cb) {
|
|||
return cb(err);
|
||||
}
|
||||
// Check if the foreign key matches the primary key
|
||||
if (inst[fk] && inst[fk].toString() === modelInstance[pk].toString()) {
|
||||
if (inst[fk] != null && inst[fk].toString() === modelInstance[pk].toString()) {
|
||||
cb(null, inst);
|
||||
} else {
|
||||
err = new Error('Key mismatch: ' + modelFrom.modelName + '.' + pk
|
||||
|
@ -1483,7 +1483,7 @@ BelongsTo.prototype.related = function (condOrRefresh, options, cb) {
|
|||
return cb(null, null);
|
||||
}
|
||||
// Check if the foreign key matches the primary key
|
||||
if (inst[pk] && modelInstance[fk]
|
||||
if (inst[pk] != null && modelInstance[fk] != null
|
||||
&& inst[pk].toString() === modelInstance[fk].toString()) {
|
||||
self.resetCache(inst);
|
||||
cb(null, inst);
|
||||
|
@ -1891,7 +1891,7 @@ HasOne.prototype.related = function (condOrRefresh, options, cb) {
|
|||
return cb(null, null);
|
||||
}
|
||||
// Check if the foreign key matches the primary key
|
||||
if (inst[fk] && modelInstance[pk]
|
||||
if (inst[fk] != null && modelInstance[pk] != null
|
||||
&& inst[fk].toString() === modelInstance[pk].toString()) {
|
||||
self.resetCache(inst);
|
||||
cb(null, inst);
|
||||
|
@ -3005,7 +3005,10 @@ ReferencesMany.prototype.findById = function (fkId, options, cb) {
|
|||
}
|
||||
|
||||
var currentIds = ids.map(function(id) { return id.toString(); });
|
||||
var id = (inst[pk] || '').toString(); // mongodb
|
||||
var id = '';
|
||||
if (inst[pk] != null) {
|
||||
id = inst[pk].toString();
|
||||
}
|
||||
|
||||
// Check if the foreign key is amongst the ids
|
||||
if (currentIds.indexOf(id) > -1) {
|
||||
|
|
Loading…
Reference in New Issue