开发者

How can I reference the same class multiple times within another class?

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'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜