title: Rails association query
body: <p>I am having trouble accessing the correct information in my rails model (which I believe to be correct) The schema for my tables are</p>
  
  <pre><code>create_table :schools do |t|
      t.string :name
      t.timestamps
  end  
  
  create_table :variables do |t|
      t.string :name
      t.string :category
      t.timestamps
  end
  
  create_table :data do |t|
      t.string :entry
      t.decimal :rank, :scale =&gt; 3
      t.integer :school_id, :null =&gt; false
      t.integer :variable_id, :null =&gt; false
      t.timestamps
  end
  </code></pre>
  
  <p>Model classes:</p>
  
  <pre><code>class Datum &lt; ActiveRecord::Base
      belongs_to :school
      belongs_to :variable
  end
  
  class School &lt; ActiveRecord::Base
      has_many :data
      has_many :variables, :through =&gt; :data
  end
  
  class Variable &lt; ActiveRecord::Base
      has_many :data
      has_many :schools, :through =&gt; :data
  end
  </code></pre>
  
  <p>here is my school show.html.erb page currently:  </p>
  
  <pre><code>&lt;h2&gt; &lt;%= @school.name %&gt; &lt;/h2&gt;
  
  &lt;table&gt;
  &lt;% @school.variables.each  do |variable| %&gt;
  &lt;tr&gt;&lt;tr/&gt;
  &lt;td&gt;&lt;%= variable.name %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= Datum.find(:first, :conditions =&gt; {:school_id =&gt; @school.id, :variable_id =&gt; variable.id}).entry %&gt;&lt;/td&gt; 
  &lt;td&gt;&lt;%= link_to 'Edit', edit_school_path(@school) %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= link_to 'Back', schools_path %&gt;&lt;/td&gt;
  &lt;% end %&gt;
  &lt;/table&gt;  
  </code></pre>
  
  <p>It does what I want it to but it does wayy to many queries.  I'm assuming I have to do eager loading but based on examples I found online I couldn't figure out how to do this (I'm really new to rails).  Does anyone have any ideas?</p>