Как реализовать has_many: через отношения с Mongoid и mongodb?

Используя этот модифицированный пример из руководства Rails , как можно смоделировать реляционную ассоциацию has_many: through с помощью mongoid?

Проблема в том, что mongoid не поддерживает has_many: through, как ActiveRecord.

# doctor checking out patient
class Physician < ActiveRecord::Base
  has_many :appointments
  has_many :patients, :through => :appointments
  has_many :meeting_notes, :through => :appointments
end

# notes taken during the appointment
class MeetingNote < ActiveRecord::Base
  has_many :appointments
  has_many :patients, :through => :appointments
  has_many :physicians, :through => :appointments
end

# the patient
class Patient < ActiveRecord::Base
  has_many :appointments
  has_many :physicians, :through => :appointments
  has_many :meeting_notes, :through => :appointments
end

# the appointment
class Appointment < ActiveRecord::Base
  belongs_to :physician
  belongs_to :patient
  belongs_to :meeting_note
  # has timestamp attribute
end

94
задан Mario Zigliotto 19 January 2015 в 20:53
поделиться