Fix multiple use of notEqualTo (#2882)
* Add failing test for multiple .notEqualTo on relation with same class * Fix multiple .notEqualTo on relations with the same class Multiple should use the union of all objectIds not the intersect Fixes ParsePlatform/parse-server#1596
This commit is contained in:
committed by
Florent Vilmart
parent
d8ba9e8b7d
commit
b88b0c578f
@@ -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) => {
|
||||
|
||||
@@ -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)) {
|
||||
@@ -696,8 +691,8 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
|
||||
$eq: query.objectId
|
||||
};
|
||||
}
|
||||
query.objectId['$nin'] = idsIntersection;
|
||||
|
||||
query.objectId['$nin'] = allIds;
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user