Wednesday 26 April 2017

API SQL foreign key reference validation

I'm developing an API on node at the moment and have a model that has a lot of foreign key references (15+) to other models.

I'd like to at least validate that the incoming POST payload contains IDs that exist in the other tables, but I'm not sure where to validate this.

If I simply try to insert it into the database, there'll be a SQL foreign key constraint error. I could capture this and attempt to relay the information to the API response.

Should I be doing each validation individually before I try the insert?



via J3Y

No comments:

Post a Comment