aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-06-03 15:57:41 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-06-24 19:21:30 +0900
commitcc93d0d47bb7b0773f4dbe0654bcd551e2762de8 (patch)
tree2b2173c1997822c39fa96054e3bc90a4222c9602 /activerecord/lib/active_record/associations
parent35a25c32da8541994274557e1c8f4a925b536acf (diff)
downloadrails-cc93d0d47bb7b0773f4dbe0654bcd551e2762de8.tar.gz
rails-cc93d0d47bb7b0773f4dbe0654bcd551e2762de8.tar.bz2
rails-cc93d0d47bb7b0773f4dbe0654bcd551e2762de8.zip
Extract `build_scope` and `predicate_builder` in `Reflection`
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb7
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb2
2 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 1593b94f0c..525cfdb028 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -138,7 +138,7 @@ module ActiveRecord
# Exclude the scope of the association itself, because that
# was already merged in the #scope method.
reflection.constraints.each do |scope_chain_item|
- item = eval_scope(reflection.klass, table, scope_chain_item, owner)
+ item = eval_scope(reflection, table, scope_chain_item, owner)
if scope_chain_item == refl.scope
scope.merge! item.except(:where, :includes)
@@ -159,9 +159,8 @@ module ActiveRecord
scope
end
- def eval_scope(klass, table, scope, owner)
- predicate_builder = PredicateBuilder.new(TableMetadata.new(klass, table))
- ActiveRecord::Relation.create(klass, table, predicate_builder).instance_exec(owner, &scope)
+ def eval_scope(reflection, table, scope, owner)
+ reflection.build_scope(table).instance_exec(owner, &scope)
end
end
end
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 97cfec0302..7fa62bfa5f 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -40,7 +40,7 @@ module ActiveRecord
constraint = build_constraint(klass, table, key, foreign_table, foreign_key)
- predicate_builder = PredicateBuilder.new(TableMetadata.new(klass, table))
+ predicate_builder = reflection.predicate_builder(table)
scope_chain_items = reflection.join_scopes(table, predicate_builder)
klass_scope = reflection.klass_join_scope(table, predicate_builder)