aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2017-03-03 11:29:05 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2017-03-03 11:29:48 -0800
commitc8e946683536e2555f98e0fa401b5a9721a9a6cb (patch)
treeb73388c52a74f1abc04f7194027d56d38b2baa5b /activerecord
parenta5651eb522bd656f21f2f2da57d6326a6bd28372 (diff)
downloadrails-c8e946683536e2555f98e0fa401b5a9721a9a6cb.tar.gz
rails-c8e946683536e2555f98e0fa401b5a9721a9a6cb.tar.bz2
rails-c8e946683536e2555f98e0fa401b5a9721a9a6cb.zip
ask reflection for klass join reflection
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb14
-rw-r--r--activerecord/lib/active_record/reflection.rb15
2 files changed, 16 insertions, 13 deletions
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