title: How to implement has_many :through relationships with Mongoid and mongodb?
body: <p>Using this modified example from <a href="http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association" rel="noreferrer">the Rails guides</a>, how does one model a relational "has_many :through" association using mongoid?</p>
  
  <p>The challenge is that mongoid does not support has_many :through as ActiveRecord does.</p>
  
  <pre><code># doctor checking out patient
  class Physician &lt; ActiveRecord::Base
    has_many :appointments
    has_many :patients, :through =&gt; :appointments
    has_many :meeting_notes, :through =&gt; :appointments
  end
  
  # notes taken during the appointment
  class MeetingNote &lt; ActiveRecord::Base
    has_many :appointments
    has_many :patients, :through =&gt; :appointments
    has_many :physicians, :through =&gt; :appointments
  end
  
  # the patient
  class Patient &lt; ActiveRecord::Base
    has_many :appointments
    has_many :physicians, :through =&gt; :appointments
    has_many :meeting_notes, :through =&gt; :appointments
  end
  
  # the appointment
  class Appointment &lt; ActiveRecord::Base
    belongs_to :physician
    belongs_to :patient
    belongs_to :meeting_note
    # has timestamp attribute
  end
  </code></pre>