Reputation: 31
The below code is written to fetch records containing "sometext" in either "name" or "description". This seems to be not working.
Can someone provide a correct way to implement "OR" searches
Side Note: "AND" function works. "OR" function is not working. sailsjs & sails-mongo version 0.94 is used.
Model.find({
where: {
or: [
{name: {contains: req.param('sometext')}},
{description: {contains: req.param('sometext')}}
]
}, limit: 15, skip: 0, sort: 'name ASC'
}, callback)
Upvotes: 3
Views: 4353
Reputation: 507
There is another way of applying OR in waterline, sails waterline provides chaining of waterline methods. The find() and where() methods can be chained as follows :
User.find({})
.where({
or: [{
name: {
'contains': searchString
}
}, {
description: {
'contains': searchString
}
}
}]
})
.skip(0)
.limit(15)
.sort({
name : 1
});
In this way, you can chain further more where
criteria.
Upvotes: 1
Reputation: 2328
This is a known bug with Sails+Waterline 0.9.4. The link goes to an issue opened by the asker. Once it is fixed, it should work using the code specified in the question.
Upvotes: 0
Reputation: 544
Model.find({
or: [
{ something: 3 },
{ somethingElse: "foo" }
]
}).done(function(err, data) {
});
Upvotes: 7