我有两个模型共享一些相同的属性,所以我想设置一个表继承结构。在做了一些研究之后,我发现我可以通过执行以下操作来使用模块来实现相同的目的:
module CommonFields
def self.included base
base.class_eval do
include DataMapper::Resource
property :type, base::Discriminator
property :enable_feature1, base::Boolean, :default => false
property :enable_feature2, base::Boolean, :default => false
end
end
end
class A
include CommonFields
property: title, String
end
class B
include CommonFields
end
但是,当我 rake db:automigrate 我得到:
CommonFields 的未定义方法“属性”:模块 /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.2.0/lib/dm-core/associations/relationship.rb:252:在“父键”中
有任何想法吗?
谢谢,
保罗