2010-12-14 126 views
1

如何使用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

references_many:sent_messages,:stored_as =>:陣列,:CLASS_NAME => '消息'

references_one:發送方,:CLASS_NAME => '用戶'

+0

和唐忘記了:inverse_of – sandrew 2010-12-15 16:42:39

+0

此解決方案在當前(2012)MongoID版本中不再適用 – Matthias 2012-05-10 22:47:40

相關問題