提交 b8380598 编写于 作者: J Jon Leighton

CollectionProxy#replace should change the DB records rather than just mutating...

CollectionProxy#replace should change the DB records rather than just mutating the array. Fixes #3020.
上级 541018a0
......@@ -46,7 +46,7 @@ class CollectionProxy # :nodoc:
delegate :select, :find, :first, :last,
:build, :create, :create!,
:concat, :delete_all, :destroy_all, :delete, :destroy, :uniq,
:concat, :replace, :delete_all, :destroy_all, :delete, :destroy, :uniq,
:sum, :count, :size, :length, :empty?,
:any?, :many?, :include?,
:to => :@association
......
......@@ -1578,4 +1578,15 @@ def test_association_attributes_are_available_to_after_initialize
assert_equal car.id, bulb.attributes_after_initialize['car_id']
end
def test_replace
car = Car.create(:name => 'honda')
bulb1 = car.bulbs.create
bulb2 = Bulb.create
assert_equal [bulb1], car.bulbs
car.bulbs.replace([bulb2])
assert_equal [bulb2], car.bulbs
assert_equal [bulb2], car.reload.bulbs
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册