Handle queries with equalTo on objectId and relation conditions (#2472)

* Add test for notEqualTo on relation with equalTo on objectId

* Properly handles queries with equalTo on objectId and relation conditions

This is done by converting shorthand $eq condition to $eq condition instead of clobbering.
This commit is contained in:
Jeremy Louie
2016-08-07 21:58:32 -04:00
committed by Drew
parent cdb46dcb2e
commit f27dff0ae6
2 changed files with 22 additions and 8 deletions

View File

@@ -647,11 +647,13 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
idsIntersection = intersect(allIds);
}
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
// is expected though.
if (!('objectId' in query) || typeof query.objectId === 'string') {
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
if (!('objectId' in query)) {
query.objectId = {};
} else if (typeof query.objectId === 'string') {
query.objectId = {
$eq: query.objectId
};
}
query.objectId['$in'] = idsIntersection;
@@ -670,11 +672,13 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
idsIntersection = intersect(allIds);
}
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
// is expected though.
if (!('objectId' in query) || typeof query.objectId === 'string') {
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
if (!('objectId' in query)) {
query.objectId = {};
} else if (typeof query.objectId === 'string') {
query.objectId = {
$eq: query.objectId
};
}
query.objectId['$nin'] = idsIntersection;