Permalink
Browse files

Merge [7075] to stable: save associated records only if the associati…

…on is already loaded. References #8713.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7076 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2ba8864 commit 7d517a145bebe3617f4a117e3685394396598182 @jeremy jeremy committed Jun 21, 2007
View
@@ -1,5 +1,7 @@
*SVN*
+* Save associated records only if the association is already loaded. #8713 [blaine]
+
* Changing the :default Date format doesn't break date quoting. #6312 [bshand, Elias]
* Allow nil serialized attributes with a set class constraint. #7293 [sandofsky]
@@ -993,8 +993,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
@@ -1004,7 +1004,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)
@@ -67,8 +67,8 @@ def test_storing_in_pstore
end
class AssociationProxyTest < Test::Unit::TestCase
- fixtures :authors, :posts
-
+ fixtures :authors, :posts, :developers, :projects, :developers_projects
+
def test_proxy_accessors
welcome = posts(:welcome)
assert_equal welcome, welcome.author.proxy_owner
@@ -87,6 +87,14 @@ def test_proxy_accessors
david.posts_with_extension.first # force load target
assert_equal david.posts_with_extension, david.posts_with_extension.testing_proxy_target
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

0 comments on commit 7d517a1

Please sign in to comment.