Rails数据库设计:使用字符串或整数? [英] Rails Database Design: Use strings or integer?

查看:141
本文介绍了Rails数据库设计:使用字符串或整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含从一组选项中选择的信息的rails表。例如,名为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆