Should frontend use ids when passing data to the backend?

Suppose I have a form the user will fill out, and it has a list of options. For example, a form for creating a user which includes:

Department: Accounting, Admin, Business, IT, Sales, etc.

In the database, those departments are:

DEPARTMENT

ID NAME
1 Accounting
2 Admin
3 Business
… …

When submitting the form to the backend, is it better to send department:1, or department:"Accounting". Sending 1 makes it easy to insert a new database entry since the id is already there. But sending the name makes it easier for the frontend because in that case, you don't even need to query the backend for the ids, which are never used on the frontend anyway. And I've always read that you should not expose database ids anyway. However, this option makes the database operation more complex as you now have to first get the department id from the name in order to insert that value as a foreign key in your user table.

submitted by /u/StuffedCrustGold
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/TGuj5JO

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free
search previous next tag category expand menu location phone mail time cart zoom edit close