提交 989332c7 编写于 作者: J Jeremy Kemper

Save associated records only if the association is already loaded. Closes #8713.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7075 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 9e446143
*SVN*
* Save associated records only if the association is already loaded. #8713 [blaine]
* MySQL: fix show_variable. #8448 [matt, Jeremy Kemper]
* Fixtures: correctly delete and insert fixtures in a single transaction. #8553 [Michael Schuerig]
......
......@@ -1100,8 +1100,8 @@ def add_multiple_associated_save_callbacks(association_name)
after_callback = <<-end_eval
association = instance_variable_get("@#{association_name}")
if association.respond_to?(:loaded?)
if association.respond_to?(:loaded?) && association.loaded?
if @new_record_before_save
records_to_save = association
else
......@@ -1111,7 +1111,7 @@ def add_multiple_associated_save_callbacks(association_name)
association.send(:construct_sql) # reconstruct the SQL queries now that we know the owner's id
end
end_eval
# Doesn't use after_save as that would save associations added in after_create/after_update twice
after_create(after_callback)
after_update(after_callback)
......
......@@ -69,7 +69,7 @@ def test_storing_in_pstore
end
class AssociationProxyTest < Test::Unit::TestCase
fixtures :authors, :posts, :categorizations, :categories
fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects
def test_proxy_accessors
welcome = posts(:welcome)
......@@ -98,6 +98,14 @@ def test_push_does_not_load_target
assert david.categories.include?(categories(:technology))
end
def test_save_on_parent_does_not_load_target
david = developers(:david)
assert !david.projects.loaded?
david.update_attribute(:created_at, Time.now)
assert !david.projects.loaded?
end
end
class HasOneAssociationsTest < Test::Unit::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册