如何在另一个类中多次引用同一个类?

时间:2010-12-14 22:23:54

标签: ruby mongodb mongoid

如何使用Mongoid在另一个类中引用同一个类两次(或多次)?

class User
  include Mongoid::Document
  field :email

  references_many :messages, :stored_as => :array #all messages where the user acts as a sender
  references_many :messages, :stored_as => :array #all messages where the user acts as a receiver
end

class Message
  include Mongoid::Document
  field :Text

  references_one :user #this should be the sender
  references_one :user #this should be the receiver
end

1 个答案:

答案 0 :(得分:0)

references_many:sent_messages,:stored_as => :array,:class_name => '消息'

references_one:sender,:class_name => '用户'