我有一个Dog
模型,可以有很多tags
和我的Tag
模型有type
列。对于type
属性我只能选择3种不同类型:如何为种子数据中的模型选择包容性选择选项?
class Tag
belongs_to :dog
TYPES = %w(Red Blue Green)
validates :type, inclusion: { :in => TYPES },
presence: true
end
在我的种子文件我有:
tags = Tag.create([ { name: "Red Terrier", type: "Red" } ])
我运行rake命令,得到错误:
rake aborted!
Invalid single-table inheritance type: Red is not a subclass of Tag
这里发生了什么?有什么办法做到这一点,为什么它认为它是一个子类?