Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 909b337da8d905afe0204cd96b033a276522441f 1 parent 18bf309
@jonleighton jonleighton authored
View
2  activerecord/lib/active_record/autosave_association.rb
@@ -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)
View
4 activerecord/lib/active_record/reflection.rb
@@ -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...)
View
14 activerecord/test/cases/associations/nested_through_associations_test.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.