From c8e946683536e2555f98e0fa401b5a9721a9a6cb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Mar 2017 11:29:05 -0800 Subject: ask reflection for klass join reflection --- .../associations/join_dependency/join_association.rb | 14 +------------- activerecord/lib/active_record/reflection.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index c28e3bb097..17670ebc0c 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -42,20 +42,8 @@ module ActiveRecord predicate_builder = PredicateBuilder.new(TableMetadata.new(klass, table)) scope_chain_items = reflection.join_scopes(table, predicate_builder) + klass_scope = reflection.klass_join_scope(table, predicate_builder) - klass_scope = - if klass.current_scope - klass.current_scope.clone.tap { |scope| - scope.joins_values = [] - } - else - relation = ActiveRecord::Relation.create( - klass, - table, - predicate_builder, - ) - klass.send(:build_default_scope, relation) - end scope_chain_items.concat [klass_scope].compact rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right| diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 02aab25610..ba40db2de9 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -196,6 +196,21 @@ module ActiveRecord end end + def klass_join_scope(table, predicate_builder) # :nodoc: + if klass.current_scope + klass.current_scope.clone.tap { |scope| + scope.joins_values = [] + } + else + relation = ActiveRecord::Relation.create( + klass, + table, + predicate_builder, + ) + klass.send(:build_default_scope, relation) + end + end + def constraints chain.map(&:scopes).flatten end -- cgit v1.2.3