提交 909b337d 编写于 作者: J Jon Leighton

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

上级 18bf3098
...@@ -343,7 +343,7 @@ def save_collection_association(reflection) ...@@ -343,7 +343,7 @@ def save_collection_association(reflection)
if autosave if autosave
saved = association.insert_record(record, false) saved = association.insert_record(record, false)
else else
association.insert_record(record) association.insert_record(record) unless reflection.nested?
end end
elsif autosave elsif autosave
saved = record.save(:validate => false) saved = record.save(:validate => false)
......
...@@ -262,6 +262,10 @@ def chain ...@@ -262,6 +262,10 @@ def chain
[self] [self]
end end
def nested?
false
end
# An array of arrays of conditions. Each item in the outside array corresponds to a reflection # 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 # in the #chain. The inside arrays are simply conditions (and each condition may itself be
# a hash, array, arel predicate, etc...) # a hash, array, arel predicate, etc...)
......
...@@ -545,6 +545,20 @@ def test_nested_has_many_through_with_foreign_key_option_on_the_source_reflectio ...@@ -545,6 +545,20 @@ def test_nested_has_many_through_with_foreign_key_option_on_the_source_reflectio
assert_equal [organizations(:nsa)], organizations assert_equal [organizations(:nsa)], organizations
end 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 private
def assert_includes_and_joins_equal(query, expected, association) def assert_includes_and_joins_equal(query, expected, association)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册