Search code examples
modelsails.jsstiwaterline

Waterline default query condition


How can I set the default where/sort condition in my SailsJS waterline model? In Rails I would use default scope.


Solution

  • Sails doesn't support default criteria on a per-model basis, but if you're using blueprint routes you can set default criteria for the route by overriding in your config/routes.js file, for example:

    "GET /user": {
        controller: 'user', 
        action: 'find', 
        where: {'deleted': false}, 
        sort: 'age DESC'
    }
    

    This will work even if you don't have a find action defined in your UserController.js file, because the blueprint is added for you by default.