开发者

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

开发者 https://www.devze.com 2023-01-30 09:05 出处:网络
How can I reference the same class twice (or multiple times) within another class with Mongoid? class User

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

精彩评论

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

关注公众号