diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-18 10:52:16 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-18 10:52:16 +0900 |
commit | d807e3f59d93dd9f590af83e708d0a21f208094a (patch) | |
tree | c57909fe44c357559f2abc7067912216353733a4 /activerecord/lib/active_record/associations/preloader | |
parent | 385d9af299fbfac7f063de214d371545bafef5df (diff) | |
download | rails-d807e3f59d93dd9f590af83e708d0a21f208094a.tar.gz rails-d807e3f59d93dd9f590af83e708d0a21f208094a.tar.bz2 rails-d807e3f59d93dd9f590af83e708d0a21f208094a.zip |
Prevent extra `through_scope`
We can reuse `through_scope` for `reset_association`.
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader')
-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 d53d3f777b..0749b038b6 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) || (reflection.options[:source_type] && through_reflection.collection?) |