7
我有這樣mongoid繼承問題
class Canvas
include Mongoid::Document
field :name
referenced_in :hero
end
class Browser < Canvas
field :version, :type => Integer
end
class Hero
include Mongoid::Document
field :name
references_many :canvases
end
如何建立從英雄對象refered布勞爾對象模型。
所有我想要做的就是
h = Hero.create!({:name => 'Aston'})
h.browsers.build
但是它給了我一個錯誤
undefined method `browsers' for #<Hero _id: 4d92c8fc1426960fff000005, name: "Aston">
我這麼想嗎?
感謝
注意到這個答案只適用Mongoid 2.0.0rc7和mongoid-2.0不起作用.0.beta.19。 – Gagan 2011-03-30 06:47:38
我通過http://modetojoy.blogspot.com/2010/01/inheritance-in-mongoid.html找到了答案 – 2011-05-12 03:48:12