1
我有兩個模型共享一些相同的屬性,所以我想設置一個表繼承結構。之後做一些研究,我發現我可以用模塊通過執行來實現相同的,而不是執行以下操作:在模型之間共享屬性 - Datamapper
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
然而,當我這樣做耙分貝:automigrate我得到:
未定義的方法`性質'for CommonFields:Module /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.2.0/lib/dm-core/associations/relationship.rb:252:in`parent_key '
任何想法?
感謝,
保羅
同樣的問題在這裏......你是怎麼做到的? –