Skip to content

Commit 4876874

Browse files
Revert "Skip persisted through targets when autosaving collection associations"
This reverts commit 0d38f2a.
1 parent 94729d0 commit 4876874

File tree

2 files changed

+1
-40
lines changed

2 files changed

+1
-40
lines changed

activerecord/lib/active_record/autosave_association.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,7 @@ def init_internals
297297
# unless the parent is/was a new record itself.
298298
def associated_records_to_validate_or_save(association, new_record, autosave)
299299
if new_record || custom_validation_context?
300-
target = association && association.target
301-
if target && association.reflection.through_reflection
302-
# We expect new through records to be autosaved by their direct parent.
303-
# This prevents already persisted through records from being validated or saved
304-
# more than once.
305-
target.find_all(&:changed_for_autosave?)
306-
else
307-
target
308-
end
300+
association && association.target
309301
elsif autosave
310302
association.target.find_all(&:changed_for_autosave?)
311303
else

activerecord/test/cases/autosave_association_test.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
require "models/cake_designer"
4141
require "models/drink_designer"
4242
require "models/cpk"
43-
require "models/family"
44-
require "models/family_tree"
45-
require "models/user"
4643

4744
class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
4845
def test_autosave_works_even_when_other_callbacks_update_the_parent_model
@@ -1150,34 +1147,6 @@ def test_autosave_new_record_with_after_create_callback_and_habtm_association
11501147

11511148
assert_equal 1, post.categories.reload.length
11521149
end
1153-
1154-
FamilyLoadingMiddleAndThroughRecordsBeforeSave = Class.new(Family) do
1155-
before_save do
1156-
family_trees.map(&:member) + members
1157-
end
1158-
end
1159-
1160-
def test_autosave_new_record_with_hmt_and_middle_record_built_by_parent
1161-
family = FamilyLoadingMiddleAndThroughRecordsBeforeSave.new
1162-
family_tree = family.family_trees.build
1163-
family_tree.build_member
1164-
family.save!
1165-
family.reload
1166-
1167-
assert_equal 1, family.family_trees.size
1168-
assert_equal 1, family.members.size
1169-
end
1170-
1171-
def test_autosave_new_record_with_hmt_and_middle_record_built_by_through_record
1172-
family = FamilyLoadingMiddleAndThroughRecordsBeforeSave.new
1173-
member = family.members.build
1174-
family.family_trees.build(member: member)
1175-
family.save!
1176-
family.reload
1177-
1178-
assert_equal 1, family.family_trees.size
1179-
assert_equal 1, family.members.size
1180-
end
11811150
end
11821151

11831152
class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase

0 commit comments

Comments
 (0)