class Report
include Mongoid::Document
embeds_many :figures
end
class Figure
include Mongoid::Document
embedded_in :report
field :legend
validates_presence_of :legend
end生成以下错误消息:
Figures is invalid我如何才能让错误消息中的多数人同意?
发布于 2012-01-24 08:26:52
从错误到可读消息的转换是由ActiveModel而不是Mongoid处理的,嵌入式模型被认为只是属性本地化方面的属性。
在这种情况下,如果您在i18n文件中使用以下代码,则通过修改human_attribute_name为图形属性返回的内容,您将获得单数形式而不是复数形式:
en:
mongoid:
attributes:
report:
figures: Figure发布于 2011-12-23 14:55:39
从Mongoid docs
你可以给你的关系起任何你喜欢的名字,但是如果Mongoid不能从名字中推断出这个类,那么你就需要给这个宏提供一些额外的选项来告诉Mongoid如何将它们连接起来。
你应该只需要使用
class Report
include Mongoid::Document
embeds_many :figures, class_name: "Figure"
end
class Figure
include Mongoid::Document
embedded_in :report, class_name: "Report"
field :legend
validates_presence_of :legend
endhttps://stackoverflow.com/questions/8607968
复制相似问题