How can I reference the same class twice (or multiple times) within another class with Mongoid?
class User
include Mongoid::Document
field :email
references_many :messages, :stored_as => :array #all messages 开发者_JAVA技巧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
references_many :sent_messages, :stored_as => :array, :class_name => 'Message'
and
references_one :sender, :class_name => 'User'
精彩评论