Search code examples
sails.jswaterlinesails-mongo

Unable to update boolean value in sailsjs waterline


I'm working on a project that is built on top of SailsJS but now i'm writing the Update process for a document and when i'm doing this, getting the following error.

   {
      "code": "E_VALIDATION",
      "invalidAttributes": {
      "deleted": [
      {
        "rule": "boolean",
        "message": "\"boolean\" validation rule failed for input: 'true'\nSpecifically, it threw an error.  Details:\n undefined"
      }
    ]}
  }

In the Model I've

    deleted: {
        type: 'string',
        boolean: true
    }

In Controller // Action for deleting a specified User destroy: function( req, res, next ) {

    // Logs actions details
    sails.log.info("Attempting to delete user ( " , req.param('id') , " ) from IP (IP adddress: " , req.ip , ")" );

    User.update({
        id: req.param('id')
    }, {
        deleted: true
    }).exec(function (err, user) {
        if (err) {

            // Handles the response containing some error
            ErrorHandler.response(err, req, res, next);
        }

        res.json(user);
    });
}

Solution

  • boolean is not a validation rule in Sails.js. You should use type: 'boolean' instead. See list of model attributes.

    In your User model:

    deleted: {
        type: 'boolean'
    }