关于引用许多其他文档的嵌入文档
我有一个以下关联
Class Person
include Mongoid::Document
embeds_many :employments
end
Class Employment
include Mongoid::Document
references_many :centres
end
class Centre
include Mongoid::Document
referenced_in :employment
end
现在,当我尝试
Person.first.employments.first.centres.build
时,它给了我错误,例如
NoMethodError: undefined method `centres' for #<Employment:0x000001023f38f8>
我做错了什么吗?
或者嵌入文档无法引用许多其他文档?
I have a following association
Class Person
include Mongoid::Document
embeds_many :employments
end
Class Employment
include Mongoid::Document
references_many :centres
end
class Centre
include Mongoid::Document
referenced_in :employment
end
Now when I tried
Person.first.employments.first.centres.build
it gave me errors like
NoMethodError: undefined method `centres' for #<Employment:0x000001023f38f8>
Am i doing any thing wrong?
Or the embedded document cannot reference many other documents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
兄弟,你设置错了。嵌入文档不能引用其他模型。如果您仍然想引用带有嵌入文档的另一个模型,那么您将必须创建自定义函数。
Dude, you setup is wrong. Embedded document cannot reference other model. If you still want to reference another model with embedded document, then you will have to create custom function.
尝试:
Try: