Waterline ORM (sails.js) conditions with NOT Equal in query

Viewed 11765

How can I write a NOT Equal condition in Waterline?

This code:

Users
  .count()
  .where({
     id: { '!=': req.params.id},
     lastname: req.body.lastname
  })

Does nothing... (disk adapter in sails.js)

3 Answers

First thing, it do nothing because looking into database is asynchronous. You have to make the chain longer and add exec or something from Q library like then.

User.count().where({
    id: { '!=': req.params.id },
    lastname: req.body.lastname
}).exec(function(err, num){
    console.log(num);
});

Now it returns 0. To make it return proper number instead of '!=' just write '!'.

I haven't used count directly, I have used length to know count.

let user = User.find({
   where: {
    id: { '!=': req.params.id },
    lastname: req.body.lastname
  }
});
let count = user.length;
Related