diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 281db8fe064d8ece9b8f385555947bdfff00ab4b..19112216aa7ec1eea21adb26db2de0c8416a613c 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -83,7 +83,7 @@ def delete(*records) raise_on_type_mismatch(associate) raise ActiveRecord::HasManyThroughCantDissociateNewRecords.new(@owner, through) unless associate.respond_to?(:new_record?) && !associate.new_record? - @owner.send(through.name).proxy_target.delete(klass.delete_all(construct_join_attributes(associate))) + klass.delete_all(construct_join_attributes(associate)) @target.delete(associate) end end diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index f59fe70654b8723a578f17a7faf94bb24cffbeed..e72c6d0e072c757bbae156af4a815573f9f99039 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -505,11 +505,13 @@ def test_delete_associate_when_deleting_from_has_many_through tag = Tag.create!(:name => 'doomed') post_thinking = posts(:thinking) post_thinking.tags << tag + assert_equal(count + 1, post_thinking.taggings(true).size) assert_equal(count + 1, post_thinking.tags(true).size) assert_nothing_raised { post_thinking.tags.delete(tag) } assert_equal(count, post_thinking.tags.size) assert_equal(count, post_thinking.tags(true).size) + assert_equal(count, post_thinking.taggings(true).size) assert_equal(tags_before.sort, post_thinking.tags.sort) end