title: Rails 3: How do I work with methods on a related object?
body: <p>I'm updating a site with Rails 3.1 and adding some features. This application tracks tests for a collection of sites. Originally I was storing the grade for each test as a column in the Tests table but now I have created a new model called Reviews to keep a history of grades and comments assigned each test. The models look like this:</p>
  
  <pre><code>class Site &lt; ActiveRecord::Base
    has_many :tests
    has_many :reviews, :through =&gt; :tests
  
  class Test &lt; ActiveRecord::Base
    has_many :reviews
    belongs_to :site
  
  class Review &lt; ActiveRecord::Base
    belongs_to :test
    has_one :user
  </code></pre>
  
  <p>Previously I could do something like this in the Site model to get some reporting data on grades:</p>
  
  <pre><code>def total_a_grades
    tests.count(:conditions =&gt; "reviewer_grade = 4 and review_status = 3")
  end
  </code></pre>
  
  <p>Since the grades are now out of the Test model I created this method to access the most recent grade for each test:</p>
  
  <pre><code>def last_grade
    return reviews.find(:last).grade
  end
  </code></pre>
  
  <p>This works fine for displaying the most recent grade in the test view, but how can I use it at the site level? Since the value is now in a method that's not stored in the database, I don't know how to work with it and can't find anything related to this at the major online tutorial/screencast sites.</p>
  
  <p>Thanks in advance for your help!</p>