我的模特在这里遇到了一个恼人的问题:
class Message
include Mongoid::Document
field :subject
field :text
field :sender_deleted, :type => Boolean, :default => false
field :recipient_deleted, :type => Boolean, :default => false
field :read_at#, :type => DateTime
referenced_in :sender, :class_name => "User", :inverse_of => :snt_msg
referenced_in :recipient, :class_name => "User", :inverse_of => :rcvd_msg
embeds_many :replies, :class_name => "Message"
embedded_in :message, :inverse_of => :replies
end
用户的这个结构:
class User
include Mongoid::Document
field :username, type: String
field :password_hash, type: String
field :password_salt, type: String
field :email, type: String
field :role, type: Boolean, default: -> {false}
references_many :snt_msg, :class_name => 'Message', :inverse_of => :sender
references_many :rcvd_msg, :class_name => 'Message', :inverse_of => :recipient
end
当我想加载包含相关表单的页面时,我收到此错误:
消息的未定义方法`referenced_in':Class
为什么会这样?
答案 0 :(得分:0)
我不确定为什么会出现“未定义的方法”错误,但您应该知道mongoid中不可能引用嵌入的文档。
尝试通过引用替换embeds_many
/ embedded_in
。