Skip to content

Fix multiple use of notEqualTo #2882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ describe('Parse.Query testing', () => {
return query.find().then(function(results){
equal(results.length, 0);
});
}).then(function(){
var query = new Parse.Query(Cake);
query.notEqualTo("hater", user2);
query.notEqualTo("liker", user2);
// user2 doesn't like any cake so this should be 0
return query.find().then(function(results){
equal(results.length, 0);
});
}).then(function(){
var query = new Parse.Query(Cake);
query.equalTo("hater", user);
query.equalTo("liker", user);
// user doesn't hate any cake so this should be 0
return query.find().then(function(results){
equal(results.length, 0);
});
}).then(function(){
done();
}).catch((err) => {
Expand Down
17 changes: 6 additions & 11 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,12 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
return query;
}

DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query) {
let idsFromNin = query.objectId && query.objectId['$nin'] ? query.objectId['$nin'] : null;
let allIds = [idsFromNin, ids].filter(list => list !== null);
let totalLength = allIds.reduce((memo, list) => memo + list.length, 0);
DatabaseController.prototype.addNotInObjectIdsIds = function(ids = [], query) {
let idsFromNin = query.objectId && query.objectId['$nin'] ? query.objectId['$nin'] : [];
let allIds = [...idsFromNin,...ids].filter(list => list !== null);

let idsIntersection = [];
if (totalLength > 125) {
idsIntersection = intersect.big(allIds);
} else {
idsIntersection = intersect(allIds);
}
// make a set and spread to remove duplicates
allIds = [...new Set(allIds)];

// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
if (!('objectId' in query)) {
Expand All @@ -696,8 +691,8 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
$eq: query.objectId
};
}
query.objectId['$nin'] = idsIntersection;

query.objectId['$nin'] = allIds;
return query;
}

Expand Down