aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-12-06 15:30:52 -0500
committerGitHub <noreply@github.com>2016-12-06 15:30:52 -0500
commit09b2e29fc602cedce6dc856ffeb5f8521c089aa5 (patch)
treecccf2d4f5586d94bec3d9bf70483b72661ae7be8 /activerecord/lib/active_record
parent91ae6e86da8174f5c4073bfce7fa6239464a4f02 (diff)
parente7f4c45bdc178c41face92e4be9ec027a07daeda (diff)
downloadrails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.tar.gz
rails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.tar.bz2
rails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.zip
Merge pull request #27251 from ebeigarts/fix-autosave
Fix association scope inside autosaved association callbacks
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index b343332bae..9d0b501862 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -383,6 +383,9 @@ module ActiveRecord
if association = association_instance_get(reflection.name)
autosave = reflection.options[:autosave]
+ # reconstruct the scope now that we know the owner's id
+ association.reset_scope if association.respond_to?(:reset_scope)
+
if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave)
if autosave
records_to_destroy = records.select(&:marked_for_destruction?)
@@ -408,9 +411,6 @@ module ActiveRecord
raise ActiveRecord::Rollback unless saved
end
end
-
- # reconstruct the scope now that we know the owner's id
- association.reset_scope if association.respond_to?(:reset_scope)
end
end