<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -51,9 +51,7 @@ module ActiveRecord
       
       def add_preloaded_record_to_collection(parent_records, reflection_name, associated_record)
         parent_records.each do |parent_record|
-          association_proxy = parent_record.send(reflection_name)
-          association_proxy.loaded
-          association_proxy.target = associated_record
+          parent_record.send(&quot;set_#{reflection_name}_target&quot;, associated_record)
         end
       end
 
@@ -112,8 +110,8 @@ module ActiveRecord
       def preload_has_one_association(records, reflection, preload_options={})
         id_to_record_map, ids = construct_id_map(records)        
         options = reflection.options
+        records.each {|record| record.send(&quot;set_#{reflection.name}_target&quot;, nil)}
         if options[:through]
-          records.each {|record| record.send(reflection.name) &amp;&amp; record.send(reflection.name).loaded}
           through_records = preload_through_records(records, reflection, options[:through])
           through_reflection = reflections[options[:through]]
           through_primary_key = through_reflection.primary_key_name
@@ -126,8 +124,6 @@ module ActiveRecord
             end
           end
         else
-          records.each {|record| record.send(&quot;set_#{reflection.name}_target&quot;, nil)}
-
           set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.primary_key_name)
         end
       end</diff>
      <filename>activerecord/lib/active_record/association_preload.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,19 +44,23 @@ class HasOneThroughAssociationsTest &lt; ActiveRecord::TestCase
   def test_has_one_through_polymorphic
     assert_equal clubs(:moustache_club), @member.sponsor_club
   end
-  
+
   def has_one_through_to_has_many
     assert_equal 2, @member.fellow_members.size
   end
-  
+
   def test_has_one_through_eager_loading
-    members = Member.find(:all, :include =&gt; :club, :conditions =&gt; [&quot;name = ?&quot;, &quot;Groucho Marx&quot;])
+    members = assert_queries(3) do #base table, through table, clubs table
+      Member.find(:all, :include =&gt; :club, :conditions =&gt; [&quot;name = ?&quot;, &quot;Groucho Marx&quot;])
+    end
     assert_equal 1, members.size
     assert_not_nil assert_no_queries {members[0].club}
   end
-  
+
   def test_has_one_through_eager_loading_through_polymorphic
-    members = Member.find(:all, :include =&gt; :sponsor_club, :conditions =&gt; [&quot;name = ?&quot;, &quot;Groucho Marx&quot;])
+    members = assert_queries(3) do #base table, through table, clubs table
+      Member.find(:all, :include =&gt; :sponsor_club, :conditions =&gt; [&quot;name = ?&quot;, &quot;Groucho Marx&quot;])
+    end
     assert_equal 1, members.size
     assert_not_nil assert_no_queries {members[0].sponsor_club}    
   end</diff>
      <filename>activerecord/test/cases/associations/has_one_through_associations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f2d8d13c6495f2a9b3bbf3b50d869c0e5b25c207</id>
    </parent>
  </parents>
  <author>
    <name>Frederick Cheung</name>
    <email>frederick.cheung@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/b7a37b742c0abd1df8ea48cc82f76385cc0c41ea</url>
  <id>b7a37b742c0abd1df8ea48cc82f76385cc0c41ea</id>
  <committed-date>2008-08-25T20:49:55-07:00</committed-date>
  <authored-date>2008-08-25T14:36:19-07:00</authored-date>
  <message>Fix preloading of has_one through associations

[#903 state:resolved]

Signed-off-by: Jeremy Kemper &lt;jeremy@bitsweat.net&gt;</message>
  <tree>2f2956ee7d2da26c1c8e13ddb0489f5eaaf0e4e4</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
