Fix the case where qWhere[idKey] is null
This commit is contained in:
parent
1f27ca57b2
commit
4a6f0a4aa0
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue