How can I set the default where/sort condition in my SailsJS waterline model? In Rails I would use default scope.
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.
来源:https://stackoverflow.com/questions/25080201/waterline-default-query-condition