Permalink
Browse files

Don't try to autosave nested assocs. Fixes #2961.

  • Loading branch information...
jonleighton committed Dec 14, 2011
1 parent 18bf309 commit 909b337da8d905afe0204cd96b033a276522441f
@@ -343,7 +343,7 @@ def save_collection_association(reflection)
if autosave
saved = association.insert_record(record, false)
else
- association.insert_record(record)
+ association.insert_record(record) unless reflection.nested?
end
elsif autosave
saved = record.save(:validate => false)
@@ -262,6 +262,10 @@ def chain
[self]
end
+ def nested?
+ false
+ end
+
# An array of arrays of conditions. Each item in the outside array corresponds to a reflection
# in the #chain. The inside arrays are simply conditions (and each condition may itself be
# a hash, array, arel predicate, etc...)
@@ -545,6 +545,20 @@ def test_nested_has_many_through_with_foreign_key_option_on_the_source_reflectio
assert_equal [organizations(:nsa)], organizations
end
+ def test_nested_has_many_through_should_not_be_autosaved
+ welcome_general, thinking_general = taggings(:welcome_general), taggings(:thinking_general)
+
+ assert_equal [welcome_general, thinking_general],
+ categorizations(:david_welcome_general).post_taggings.order('taggings.id')
+
+ c = Categorization.new
+ c.author = authors(:david)
+ c.post_taggings.to_a
+ assert !c.post_taggings.empty?
+ c.save
+ assert !c.post_taggings.empty?
+ end
+
private
def assert_includes_and_joins_equal(query, expected, association)

0 comments on commit 909b337

Please sign in to comment.