title: Rails using has_many through associations
body: <p>this is a noob question- i have 3 associated tables i am trying to access.</p>
  
  <p>The Patient model has:</p>
  
  <pre><code>has_many :charts
  has_many :providers, :through =&gt; :charts
  </code></pre>
  
  <p>The Provider model has:</p>
  
  <pre><code>has_many :charts 
  has_many :patients, :through =&gt; :charts
  </code></pre>
  
  <p>and the Chart model has:</p>
  
  <pre><code>belongs_to :patient
  belongs_to :provider
  </code></pre>
  
  <p>i pull the current_user.id to setup the @provider which works fine.</p>
  
  <pre><code>@provider = Provider.where(:user_id =&gt; current_user.id).first    
  </code></pre>
  
  <p>then i use that @provider.id to create a hash of charts i need which also works</p>
  
  <pre><code>@charts = Chart.where(:provider_id =&gt; @provider.id)
  </code></pre>
  
  <p>but then when i try to create a hash of the patients from the @charts hash it breaks....</p>
  
  <pre><code>@patients = Patient.where(:id =&gt; @charts.patient_id)
  </code></pre>
  
  <p>says 'undefined method `patient_id' for #'
  [patient_id is one of the columns in the charts table]</p>
  
  <p>What am i doing wrong? Help! </p>