2

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

xpepermint
  • 35,055
  • 30
  • 109
  • 163

1 Answers1

1

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.

sgress454
  • 24,870
  • 4
  • 74
  • 92