Как я могу ссылаться на один и тот же класс несколько раз внутри другого класса? - PullRequest
1 голос
/ 15 декабря 2010

Как я могу ссылаться на один и тот же класс дважды (или несколько раз) внутри другого класса с помощью 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

1 Ответ

0 голосов
/ 15 декабря 2010

reference_many: sent_messages,: сохранено_as =>: массив,: имя_класса => 'Сообщение'

и

reference_one: отправитель,: имя_класса => 'Пользователь'

...