I would like to know how to add "OR" condition in waterline query. Should look like:
User.find().where({
score: { '>': req.params.score},
status: 'user'
OR
status: 'admin'
}).exec(function(err, data){
...
});
So we have 2 conditions:
1) Score > specific number
And 2) status = user
OR
1) Status = admin.
There was an issue with the development database used by sails (waterline-criteria). The issue was the way strings and integers were handled in sails-disk. In the query criteria below, theScore, was being treated as a string. This has been resolved, so you just need to update sails-disk. You can do this by using npm install sails-disk --force --save
. After that the example below should work fine.
You can try this (Updated):
foo: function(req, res, next) {
var theScore = req.param('id') || 0;
User.find().where({
or: [{
score: {
'>': parseInt(theScore),
},
status: 'user'
},
{ status: 'admin'}]
}).exec(function(err, data) {
if (err) return next(err);
res.json(data);
});
},