From 990a938cf7527b654cef06674f25f3632920bad7 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Fri, 5 Oct 2012 18:36:44 -0400 Subject: Fix has_many assocation w/select load after create If you create a new record via a collection association proxy that has not loaded its target, and which selects additional attributes through the association, then when the proxy loads its target, it will inadvertently trigger a deprecation notice during attribute writing when CollectionAssociation#merge_target_lists attempts to do its thing, since the newly loaded records will possess attributes the created record does not. --- activerecord/test/cases/associations/join_model_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index f4592f7d0e..8bd44e6444 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -236,6 +236,14 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase assert_equal "2", categories(:sti_test).authors_with_select.first.post_id.to_s end + def test_create_through_has_many_with_piggyback + category = categories(:sti_test) + ernie = category.authors_with_select.create(:name => 'Ernie') + assert_not_deprecated do + assert_equal ernie, category.authors_with_select.detect {|a| a.name == 'Ernie'} + end + end + def test_include_has_many_through posts = Post.find(:all, :order => 'posts.id') posts_with_authors = Post.find(:all, :include => :authors, :order => 'posts.id') -- cgit v1.2.3