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
How can I build Brower Object引用自Hero对象。
我想做的就是
h = Hero.create!({:name => 'Aston'})
h.browsers.build
但是它给了我一个错误
undefined method `browsers' for #<Hero _id: 4d92c8fc1426960fff000005, name: "Aston">
我错过了什么吗?
谢谢
I have a model like this
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
How can I build Brower Object refered from Hero object.
All i want to do is
h = Hero.create!({:name => 'Aston'})
h.browsers.build
However it gave me an error
undefined method `browsers' for #<Hero _id: 4d92c8fc1426960fff000005, name: "Aston">
Am i missing something?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,
这适用于 mongoid.2.0.0.rc7
try this
this works for mongoid.2.0.0.rc7