title: query optimization in rails
body: <p>I have the following two models</p>
  
  <pre><code>class Creative &lt; ActiveRecord::Base
    belongs_to :creative_size
  end
  
  class CreativeSize &lt; ActiveRecord::Base
    has_many :creatives
  end
  </code></pre>
  
  <p>In an effort to minimize database hits, I'd like to perform one query which joins the two tables and gives me access to creatives and their sizes without needing to touch the database again. The following gets the job done:</p>
  
  <p>>> query = Creative.all :joins => :creative_size<br>
  >> query[0].creative_size.common_name</p>
  
  <p>However, I'd really like to have an instance method in Creative</p>
  
  <pre><code>def name_of_size
    self.creative_size.common_name
  end
  </code></pre>
  
  <p>but when I do so, the following code makes two database queries:</p>
  
  <p>>> query = Creative.all :joins => :creative_size<br>
  >> query[0].name_of_size</p>
  
  <p>Is there any way to use Creative#name_of_size without hitting the db again? Thanks.</p>