Difference between table and underline in rails

Not sure if the difference between underscore (student_state) and tableize (student_states) other than tableize is also pluralized. However, they are not sure how they can be used otherwise. Obviously, you can use tableize to refer to the table name in the database. But what other functions emphasize, for example, when you see: student_state compared to: student_states when used as characters. Thanks for the suggestions.

+4
source share
1 answer

tableize will pluralize your row if the original was single or multiple, and underscore will only add underscores.

Although this may seem trivial, it all refers to abstracting the details of the database implementation from the developer. If in the future Rails began to format table names differently, the only way to change it would be tableize . All other places in the Rails code that reference table names can remain unchanged, because they still call the tableize method. Therefore, a change in the basic structure of the rails is limited and much less destructive.

This is called "orthogonality" in computer science. Now that you know what this means, try to drop it in a conversation to make yourself look smarter. Did it work for me? :)

+10
source

Source: https://habr.com/ru/post/1299802/


All Articles