diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 29a4b655e1..60985aa793 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -117,6 +117,16 @@ describe('Parse.Query testing', () => { let cake = results[0]; expect(cake.id).toBe(cake3.id); }); + }).then(function(){ + var query = new Parse.Query(Cake); + // Exclude user1 + query.notEqualTo("liker", user1); + // Only cake1 + query.equalTo("objectId", cake1.id) + // user1 likes cake1 so this should return no results + return query.find().then(function(results){ + equal(results.length, 0); + }); }).then(function(){ done(); }) diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index f286907f13..96331322d0 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -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;