javascriptnode.jsormsails.jswaterline

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


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)


Solution

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