diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-28 17:36:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 17:36:13 -0400 |
commit | 3c101453cb6611b71017d83efeae0507a82fec46 (patch) | |
tree | aac9e56bd202e8a7210dfda3ed2b9d7969c65da6 /activerecord | |
parent | 65b02ea56026b8747be65d64d99d6c90f7d04083 (diff) | |
parent | d807e3f59d93dd9f590af83e708d0a21f208094a (diff) | |
download | rails-3c101453cb6611b71017d83efeae0507a82fec46.tar.gz rails-3c101453cb6611b71017d83efeae0507a82fec46.tar.bz2 rails-3c101453cb6611b71017d83efeae0507a82fec46.zip |
Merge pull request #29129 from kamipo/prevent_extra_through_scope
Prevent extra `through_scope`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index 8b954138cd..34587fd3f5 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -11,6 +11,8 @@ module ActiveRecord end def associated_records_by_owner(preloader) + through_scope = through_scope() + preloader.preload(owners, through_reflection.name, through_scope) @@ -20,7 +22,7 @@ module ActiveRecord [owner, Array(center)] end - reset_association owners, through_reflection.name + reset_association(owners, through_reflection.name, through_scope) middle_records = through_records.flat_map(&:last) @@ -63,7 +65,7 @@ module ActiveRecord id_map end - def reset_association(owners, association_name) + def reset_association(owners, association_name, through_scope) should_reset = (through_scope != through_reflection.klass.unscoped) || (options[:source_type] && through_reflection.collection?) |