Reputation: 115
I have a Class that help me to keep a range of values, it consist in 3 columns named min, max and price. When the user give me a number (example quantity=5) I need to search all the prices that the quantity satisfy this rule: quantity=5 min >= quantity AND max <= quantity
var quantity = Number(req.body.quantity);
var Range = Parse.Object.extend("PriceRange");
var query = new Parse.Query(Range);
query.limit(1000);
query.greaterThanOrEqualTo("min",quantity);
query.lessThanOrEqualTo("max",quantity);
When I make this the result is always 0 and I have a row that is min = 1, max = 10 and price = 10
What is wrong? Parse don´t let me do querys like that?
Upvotes: 1
Views: 477
Reputation: 62676
It looks like the inequalities are reversed.
query.greaterThanOrEqualTo("min",quantity); // means: min >= quantity
query.lessThanOrEqualTo("max",quantity); // means: max <= quantity
...constrains the query to find objects where the value of min is greater than quantity, and likewise for the other constraint.
Those two constraints together present an impossible condition: where some number is both smaller than some small number and larger than some large number. Fix by reversing...
query.lessThanOrEqualTo("min",quantity); // where min <= quantity
query.greaterThanOrEqualTo("max",quantity); // where max >= quantity
Upvotes: 1