title: Why is Rails ActiveRecord hitting the database twice?
body: <pre><code>@integration = Integration.first(:conditions=&gt; {:integration_name =&gt; params[:integration_name]}, :joins =&gt; :broker, :select =&gt; ['`integrations`.*, `brokers`.*'])
  $stderr.puts @integration.broker.id # This line causes Brokers to be queried again
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>Integration Load (0.4ms)   SELECT `integrations`.*, `brokers`.* FROM `integrations` INNER JOIN `brokers` ON `brokers`.id = `integrations`.broker_id WHERE (`integrations`.`integration_name` = 'chicke') LIMIT 1
  Integration Columns (1.5ms)   SHOW FIELDS FROM `integrations`
  Broker Columns (1.6ms)   SHOW FIELDS FROM `brokers`
  Broker Load (0.3ms)   SELECT * FROM `brokers` WHERE (`brokers`.`id` = 1) 
  </code></pre>
  
  <p>Any ideas why Rails would hit the databse again for <code>brokers</code> even though I already joined/selected them?</p>
  
  <p>Here are the models (Broker -> Integration is a 1-to-many relationship).  Note that this is incomplete, and I have only included the lines that establish their relationship</p>
  
  <pre><code>class Broker &lt; ActiveRecord::Base
  
    # ActiveRecord Associations
    has_many :integrations
  
  class Integration &lt; ActiveRecord::Base
  
    belongs_to :broker
  </code></pre>
  
  <p>I'm using Rails/ActiveRecord 2.3.14, so keep that in mind.</p>
  
  <p>When I do <code>Integration.first(:conditions=&gt; {:integration_name =&gt; params[:integration_name]}, :include =&gt; :broker)</code> that line causes two <code>SELECT</code>s</p>
  
  <pre><code>Integration Load (0.6ms)   SELECT * FROM `integrations` WHERE (`integrations`.`integration_name` = 'chicke') LIMIT 1
    Integration Columns (2.4ms)   SHOW FIELDS FROM `integrations`
    Broker Columns (1.9ms)   SHOW FIELDS FROM `brokers`
    Broker Load (0.3ms)   SELECT * FROM `brokers` WHERE (`brokers`.`id` = 1) 
  </code></pre>