title: Avoiding db hits in ActiveRecord
body: <p>When I assign a database find to an instance variable in Rails, why do future requests to that variable also hit the database?  Can this be avoided?</p>
  
  <p>For example, I have 3 models: User, Resource, Opinion, with has_many :through on Opinion</p>
  
  <pre><code>@opinions = current_user.opinions # pulls in all of the user's opinions, which include respective resource ids
  </code></pre>
  
  1. Calling for resource_id directly does not hit the database:
  
  <pre><code>@opinions.each do |opinion|
    opinion.resource_id  # does not hit the database (as expected)
  end
  </code></pre>
  
  2. Performing a query does hit the database (even though variable has been assigned):
  
  <pre><code>@opinions.find_by_resource_id(1) # DOES hit the database
  </code></pre>
  
  <p>Why does #2 hit the database?  Is there a way to perform the same find without hitting the database?  </p>
  
  <p>The information is already contained in the @opinions variable, so a db call does not seem necessary. </p>