Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed that has_many.create ended up with duplicate objects (closes #5250

) [daniel@nouvelles-solutions.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4416 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 16716090632d499eb6bfc8afdea2784eb6f5963d 1 parent 01a52dd
@dhh dhh authored
View
2  activerecord/lib/active_record/associations/has_many_association.rb
@@ -114,7 +114,7 @@ def load_target
begin
if !loaded?
if @target.is_a?(Array) && @target.any?
- @target = find_target + @target
+ @target = (find_target + @target).uniq
else
@target = find_target
end
View
8 activerecord/test/associations_test.rb
@@ -460,6 +460,14 @@ def test_adding
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 }
Please sign in to comment.
Something went wrong with that request. Please try again.