<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>activerecord/test/fixtures/organizations.yml</filename>
    </added>
    <added>
      <filename>activerecord/test/models/member_detail.rb</filename>
    </added>
    <added>
      <filename>activerecord/test/models/organization.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -8,11 +8,10 @@ module ActiveRecord
         current_object = @owner.send(@reflection.through_reflection.name)
         
         if current_object
-          klass.destroy(current_object)
-          @owner.clear_association_cache
+          current_object.update_attributes(construct_join_attributes(new_value))
+        else
+          @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
         end
-        
-        @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
       end
       
     private</diff>
      <filename>activerecord/lib/active_record/associations/has_one_through_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,9 +3,11 @@ require 'models/club'
 require 'models/member'
 require 'models/membership'
 require 'models/sponsor'
+require 'models/organization'
+require 'models/member_detail'
 
 class HasOneThroughAssociationsTest &lt; ActiveRecord::TestCase
-  fixtures :members, :clubs, :memberships, :sponsors
+  fixtures :members, :clubs, :memberships, :sponsors, :organizations
   
   def setup
     @member = members(:groucho)
@@ -120,4 +122,40 @@ class HasOneThroughAssociationsTest &lt; ActiveRecord::TestCase
     clubs(:moustache_club).send(:private_method)
     @member.club.send(:private_method)
   end
+
+  def test_assigning_to_has_one_through_preserves_decorated_join_record
+    @organization = organizations(:nsa)
+    assert_difference 'MemberDetail.count', 1 do
+      @member_detail = MemberDetail.new(:extra_data =&gt; 'Extra')
+      @member.member_detail = @member_detail
+      @member.organization = @organization
+    end
+    assert_equal @organization, @member.organization
+    assert @organization.members.include?(@member)
+    assert_equal 'Extra', @member.member_detail.extra_data
+  end
+
+  def test_reassigning_has_one_through
+    @organization = organizations(:nsa)
+    @new_organization = organizations(:discordians)
+
+    assert_difference 'MemberDetail.count', 1 do
+      @member_detail = MemberDetail.new(:extra_data =&gt; 'Extra')
+      @member.member_detail = @member_detail
+      @member.organization = @organization
+    end
+    assert_equal @organization, @member.organization
+    assert_equal 'Extra', @member.member_detail.extra_data
+    assert @organization.members.include?(@member)
+    assert !@new_organization.members.include?(@member)
+
+    assert_no_difference 'MemberDetail.count' do
+      @member.organization = @new_organization
+    end
+    assert_equal @new_organization, @member.organization
+    assert_equal 'Extra', @member.member_detail.extra_data
+    assert !@organization.members.include?(@member)
+    assert @new_organization.members.include?(@member)
+  end
+
 end</diff>
      <filename>activerecord/test/cases/associations/has_one_through_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,4 +6,6 @@ class Member &lt; ActiveRecord::Base
   has_one :favourite_club, :through =&gt; :memberships, :conditions =&gt; [&quot;memberships.favourite = ?&quot;, true], :source =&gt; :club
   has_one :sponsor, :as =&gt; :sponsorable
   has_one :sponsor_club, :through =&gt; :sponsor
+  has_one :member_detail
+  has_one :organization, :through =&gt; :member_detail
 end
\ No newline at end of file</diff>
      <filename>activerecord/test/models/member.rb</filename>
    </modified>
    <modified>
      <diff>@@ -197,6 +197,12 @@ ActiveRecord::Schema.define do
     t.string :name
   end
 
+  create_table :member_details, :force =&gt; true do |t|
+    t.integer :member_id
+    t.integer :organization_id
+    t.string :extra_data
+  end
+
   create_table :memberships, :force =&gt; true do |t|
     t.datetime :joined_on
     t.integer :club_id, :member_id
@@ -249,6 +255,10 @@ ActiveRecord::Schema.define do
     t.integer :shipping_customer_id
   end
 
+  create_table :organizations, :force =&gt; true do |t|
+    t.string :name
+  end
+
   create_table :owners, :primary_key =&gt; :owner_id ,:force =&gt; true do |t|
     t.string :name
   end</diff>
      <filename>activerecord/test/schema/schema.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>31be959de746da0b704684e858d1ca69dbf6bf7f</id>
    </parent>
  </parents>
  <author>
    <name>Matt Jones</name>
    <login></login>
    <email>al2o3cr@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/d3fd9971093101712e4cc97ccc534631888b673d</url>
  <id>d3fd9971093101712e4cc97ccc534631888b673d</id>
  <committed-date>2008-11-15T09:20:39-08:00</committed-date>
  <authored-date>2008-11-14T22:59:12-08:00</authored-date>
  <message>fix assignment to has_one :through associations.

Signed-off-by: Michael Koziarski &lt;michael@koziarski.com&gt;</message>
  <tree>5a26a28aeef593529ee7acf952da57ef7f0fe3c7</tree>
  <committer>
    <name>Michael Koziarski</name>
    <login>NZKoz</login>
    <email>michael@koziarski.com</email>
  </committer>
</commit>
