2

I have a Sails API where a certain model (Role) needs to return data different to the default. I have written a method in the controller to send back the data I want, but if I set up a route in config/routes.js like so:

'GET /role/:id': 'RoleController.readRole'

It takes precedence over other routes set up like http://localhost:1337/role/count/ or http://localhost:1337/role?limit=10&populate=user&sort=createdAt+DESC

How can I overwrite the findOne method only for the Role model and leave everything else the same? As far as I can see Sails only lets me overwrite a blueprint for all models.

BeaverusIV
  • 988
  • 1
  • 11
  • 26

1 Answers1

3

According to this Stack Overflow answer you can override methods if you name a method the same in your controller, so changing readRole to findOne solved my problem.

Community
  • 1
  • 1
BeaverusIV
  • 988
  • 1
  • 11
  • 26