S. Kaushika
S. Kaushika

Reputation: 9

Sails Js blueprint update without primary key

In sails Blueprint API, update action is defined as PATCH /:model/:id. Here 'id' is the primary key of the model. But I need to find a record not from the 'id' but from another column value and update another column value. How can I do this with sails blueprint API?

Upvotes: 0

Views: 55

Answers (1)

Kelvin Omereshone
Kelvin Omereshone

Reputation: 826

The PATCH /:model/:id is a shadow route(blueprint routes) that allow you quickly have RESTful routes for your models in Sails and as such the signature of it can't be altered.

However, you can opt into writing custom routes and an accompanying custom action since you want to have a more custom way of handling requests to such routes.

You can define the route in config/routes.js and bind it to a custom action where you can now query with other criteria using the WQL(Waterline Query Language)

You can check here on how to write such actions in Sails(you should be writing actions2 style actions if you are in Sails v1 so the article show you how to do that)

https://blog.sailscasts.com/migrating-your-sails-actions-to-actions2/

Upvotes: 0

Related Questions