Rails数据库设计:使用字符串或整数? [英] Rails Database Design: Use strings or integer?
问题描述
sex
的字段可以是男性
或女性
。名为 Bodytype
的字段将为 slim
, curvy
我的问题是,更好的做法是将这些值存储为整数或字符串?
在第一种情况下,当然整数将被转换为文本(在控制器中)。
感谢您的帮助。 >
如果你没有存储数百万条记录,将它们存储为字符串是好的。你失去的是快速更新这些类别的能力,但是如果它们几乎是静态的,并且不会随着时间的推移而改变,那就不重要了。性别可能称为性别和Bodytype body_type。
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.
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.
这篇关于Rails数据库设计:使用字符串或整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!