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

Igor picture Igor · Dec 4, 2013 · Viewed 10.5k times · Source

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)

Answer

Paweł Wszoła picture Paweł Wszoła · Dec 5, 2013

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 '!'.