如何使用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
答案 0 :(得分:0)
references_many:sent_messages,:stored_as => :array,:class_name => '消息'
和
references_one:sender,:class_name => '用户'