1

我的模型在这里遇到了一个烦人的问题:

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

当我想在其中加载带有关联表单的页面时,出现此错误:

Message:Class 的未定义方法“referenced_in”

为什么会这样?

  • MongoDB外壳版本:2.4.6
  • 红宝石 2.0.0p247
  • 导轨 4.0.0
4

1 回答 1

0

我不确定您为什么会收到“未定义的方法”错误,但您应该知道在 mongoid 中无法引用嵌入式文档。

尝试通过引用替换您的embeds_many/ 。embedded_in

于 2013-11-14T09:23:01.120 回答