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:
@@ -117,6 +117,16 @@ describe('Parse.Query testing', () => {
|
|||||||
let cake = results[0];
|
let cake = results[0];
|
||||||
expect(cake.id).toBe(cake3.id);
|
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(){
|
}).then(function(){
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -647,11 +647,13 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
|
|||||||
idsIntersection = intersect(allIds);
|
idsIntersection = intersect(allIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
|
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
|
||||||
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
|
if (!('objectId' in query)) {
|
||||||
// is expected though.
|
|
||||||
if (!('objectId' in query) || typeof query.objectId === 'string') {
|
|
||||||
query.objectId = {};
|
query.objectId = {};
|
||||||
|
} else if (typeof query.objectId === 'string') {
|
||||||
|
query.objectId = {
|
||||||
|
$eq: query.objectId
|
||||||
|
};
|
||||||
}
|
}
|
||||||
query.objectId['$in'] = idsIntersection;
|
query.objectId['$in'] = idsIntersection;
|
||||||
|
|
||||||
@@ -670,11 +672,13 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
|
|||||||
idsIntersection = intersect(allIds);
|
idsIntersection = intersect(allIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
|
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
|
||||||
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
|
if (!('objectId' in query)) {
|
||||||
// is expected though.
|
|
||||||
if (!('objectId' in query) || typeof query.objectId === 'string') {
|
|
||||||
query.objectId = {};
|
query.objectId = {};
|
||||||
|
} else if (typeof query.objectId === 'string') {
|
||||||
|
query.objectId = {
|
||||||
|
$eq: query.objectId
|
||||||
|
};
|
||||||
}
|
}
|
||||||
query.objectId['$nin'] = idsIntersection;
|
query.objectId['$nin'] = idsIntersection;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user