Skip to content

Commit f27dff0

Browse files
JeremyPleasedrew-gross
authored andcommitted
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.
1 parent cdb46dc commit f27dff0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

spec/ParseQuery.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ describe('Parse.Query testing', () => {
117117
let cake = results[0];
118118
expect(cake.id).toBe(cake3.id);
119119
});
120+
}).then(function(){
121+
var query = new Parse.Query(Cake);
122+
// Exclude user1
123+
query.notEqualTo("liker", user1);
124+
// Only cake1
125+
query.equalTo("objectId", cake1.id)
126+
// user1 likes cake1 so this should return no results
127+
return query.find().then(function(results){
128+
equal(results.length, 0);
129+
});
120130
}).then(function(){
121131
done();
122132
})

src/Controllers/DatabaseController.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,13 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) {
647647
idsIntersection = intersect(allIds);
648648
}
649649

650-
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
651-
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
652-
// is expected though.
653-
if (!('objectId' in query) || typeof query.objectId === 'string') {
650+
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
651+
if (!('objectId' in query)) {
654652
query.objectId = {};
653+
} else if (typeof query.objectId === 'string') {
654+
query.objectId = {
655+
$eq: query.objectId
656+
};
655657
}
656658
query.objectId['$in'] = idsIntersection;
657659

@@ -670,11 +672,13 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
670672
idsIntersection = intersect(allIds);
671673
}
672674

673-
// Need to make sure we don't clobber existing $lt or other constraints on objectId.
674-
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints
675-
// is expected though.
676-
if (!('objectId' in query) || typeof query.objectId === 'string') {
675+
// Need to make sure we don't clobber existing shorthand $eq constraints on objectId.
676+
if (!('objectId' in query)) {
677677
query.objectId = {};
678+
} else if (typeof query.objectId === 'string') {
679+
query.objectId = {
680+
$eq: query.objectId
681+
};
678682
}
679683
query.objectId['$nin'] = idsIntersection;
680684

0 commit comments

Comments
 (0)