diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-06-03 15:57:41 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-06-24 19:21:30 +0900 |
commit | cc93d0d47bb7b0773f4dbe0654bcd551e2762de8 (patch) | |
tree | 2b2173c1997822c39fa96054e3bc90a4222c9602 /activerecord/lib/active_record/associations | |
parent | 35a25c32da8541994274557e1c8f4a925b536acf (diff) | |
download | rails-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.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 2 |
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) |