Fix the case where qWhere[idKey] is null

This commit is contained in:
Tetsuo Seto 2017-06-07 10:01:07 -07:00
parent 1f27ca57b2
commit 4a6f0a4aa0
2 changed files with 16 additions and 1 deletions

View File

@ -130,7 +130,13 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
return mergedWhere; return mergedWhere;
}; };
if (queryRelated.where !== undefined) { if (queryRelated.where !== undefined) {
queryRelated.where = buildWhere(); if (!queryRelated.where[IdKey]) {
// If it's null, don't bother calling smartMerge or model.find.
// Simply return an empty result to the client.
return cb(null, []);
} else {
queryRelated.where = buildWhere();
}
} else { } else {
queryRelated.where = {}; queryRelated.where = {};
queryRelated.where[IdKey] = collectTargetIds(data, IdKey); queryRelated.where[IdKey] = collectTargetIds(data, IdKey);

View File

@ -819,6 +819,15 @@ describe('relations', function() {
done(); done();
}); });
}); });
it('returns empty result when filtering with wrong id key', function(done) {
var wrongWhereFilter = {where: {wrongIdKey: samplePatientId}};
physician.patients(wrongWhereFilter, function(err, ch) {
if (err) return done(err);
should.exist(ch);
ch.should.have.lengthOf(0);
done();
});
});
it('returns patients where id in an array', function(done) { it('returns patients where id in an array', function(done) {
var idArr = []; var idArr = [];
var whereFilter; var whereFilter;