mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
01a52dd1ad
commit
1671609063
2 changed files with 9 additions and 1 deletions
|
@ -114,7 +114,7 @@ module ActiveRecord
|
||||||
begin
|
begin
|
||||||
if !loaded?
|
if !loaded?
|
||||||
if @target.is_a?(Array) && @target.any?
|
if @target.is_a?(Array) && @target.any?
|
||||||
@target = find_target + @target
|
@target = (find_target + @target).uniq
|
||||||
else
|
else
|
||||||
@target = find_target
|
@target = find_target
|
||||||
end
|
end
|
||||||
|
|
|
@ -461,6 +461,14 @@ class HasManyAssociationsTest < Test::Unit::TestCase
|
||||||
assert_equal natural, companies(:first_firm).clients_of_firm.last
|
assert_equal natural, companies(:first_firm).clients_of_firm.last
|
||||||
end
|
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
|
def test_adding_a_mismatch_class
|
||||||
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }
|
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << nil }
|
||||||
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << 1 }
|
assert_raises(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).clients_of_firm << 1 }
|
||||||
|
|
Loading…
Reference in a new issue