diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 660e005348..d00ac96540 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -114,7 +114,7 @@ module ActiveRecord begin if !loaded? if @target.is_a?(Array) && @target.any? - @target = find_target + @target + @target = (find_target + @target).uniq else @target = find_target end diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 4c8d169566..4d8817568f 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -460,6 +460,14 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal 2, companies(:first_firm).clients_of_firm(true).size # checking using the db assert_equal natural, companies(:first_firm).clients_of_firm.last end + + def test_adding_using_create + first_firm = companies(:first_firm) + assert_equal 2, first_firm.plain_clients.size + natural = first_firm.plain_clients.create(:name => "Natural Company") + assert_equal 3, first_firm.plain_clients.length + assert_equal 3, first_firm.plain_clients.size + end def test_adding_a_mismatch_class assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }