提交 df0765d8 编写于 作者: M Michael Koziarski

Make sure that << works on has_many associations on unsaved records. Closes #9989 [hasmanyjosh]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8049 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 d44ce1cb
*SVN* *SVN*
* Make sure that << works on has_many associations on unsaved records. Closes #9989 [hasmanyjosh]
* Allow association redefinition in subclasses. #9346 [wildchild] * Allow association redefinition in subclasses. #9346 [wildchild]
* Fix has_many :through delete with custom foreign keys. #6466 [naffis] * Fix has_many :through delete with custom foreign keys. #6466 [naffis]
......
...@@ -17,6 +17,7 @@ def reset ...@@ -17,6 +17,7 @@ def reset
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically. # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
def <<(*records) def <<(*records)
result = true result = true
load_target if @owner.new_record?
@owner.transaction do @owner.transaction do
flatten_deeper(records).each do |record| flatten_deeper(records).each do |record|
......
...@@ -103,6 +103,13 @@ def test_push_does_not_load_target ...@@ -103,6 +103,13 @@ def test_push_does_not_load_target
assert david.categories.include?(categories(:technology)) assert david.categories.include?(categories(:technology))
end end
def test_push_does_not_lose_additions_to_new_record
josh = Author.new(:name => "Josh")
josh.posts << Post.new(:title => "New on Edge", :body => "More cool stuff!")
assert josh.posts.loaded?
assert_equal 1, josh.posts.size
end
def test_save_on_parent_does_not_load_target def test_save_on_parent_does_not_load_target
david = developers(:david) david = developers(:david)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册