假设我有一个相当小的(~3-10)和静态的类别集。创建专用Category
模型或使用类似哈希的结构之间的权衡是什么?例如......
class Something < ActiveRecord::Base
# Using a Category model
belongs_to :category
default_scope :include => :category
# Using a hash-like structure
CATEGORIES = ["A", "B", "C", "D", "E"]
def category
CATEGORIES[category_id]
end
# validate_inclusion_of :category_id as appropriate
...
end
答案 0 :(得分:1)
类别表的好处:
将“类别”存储为字符串而没有其他数据库表的好处