Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Database Design: Use strings or integer?

Suppose I have a rails tables containing information chosen from a set number of options. For example, a field named sex could be either Male or Female. A field named Bodytype will be either slim, curvy, etc. My question is, what is better practice, to store those values as integers or strings? In the first case, of course, the integers will be converted into text (In the controller?).

Thanks for all your help.

like image 860
TimmyOnRails Avatar asked May 21 '26 13:05

TimmyOnRails


1 Answers

If are you are not storing millions of records, storing them as strings is fine. What you are loosing is ability to quickly update these categories, but if they are pretty much static and not going to change over time, it shouldn't matter. Sex should probably be called gender and Bodytype body_type.

like image 146
iouri Avatar answered May 23 '26 04:05

iouri