diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-06-26 03:19:24 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-06-26 03:19:24 +0900 |
commit | c9cf8b8dd4b968e21768f495d6ed0861a6efe08c (patch) | |
tree | d7c011e66531185409af9eafc614ef11d974db55 /activerecord | |
parent | cc93d0d47bb7b0773f4dbe0654bcd551e2762de8 (diff) | |
download | rails-c9cf8b8dd4b968e21768f495d6ed0861a6efe08c.tar.gz rails-c9cf8b8dd4b968e21768f495d6ed0861a6efe08c.tar.bz2 rails-c9cf8b8dd4b968e21768f495d6ed0861a6efe08c.zip |
Move constructing join scope to `Reflection`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 15 |
2 files changed, 12 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 7fa62bfa5f..95f16c622e 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -40,15 +40,7 @@ module ActiveRecord constraint = build_constraint(klass, table, key, foreign_table, foreign_key) - predicate_builder = reflection.predicate_builder(table) - scope_chain_items = reflection.join_scopes(table, predicate_builder) - klass_scope = reflection.klass_join_scope(table, predicate_builder) - - scope_chain_items.concat [klass_scope].compact - - rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right| - left.merge right - end + rel = reflection.join_scope(table) if rel && !rel.arel.constraints.empty? binds += rel.bound_attributes diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index c4b58386fa..c6aa2ed720 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -185,6 +185,14 @@ module ActiveRecord end deprecate :scope_chain + def join_scope(table) + predicate_builder = predicate_builder(table) + scope_chain_items = join_scopes(table, predicate_builder) + klass_scope = klass_join_scope(table, predicate_builder) + + scope_chain_items.inject(klass_scope || scope_chain_items.shift, &:merge!) + end + def join_scopes(table, predicate_builder) # :nodoc: if scope [build_scope(table, predicate_builder).instance_exec(&scope)] @@ -286,16 +294,15 @@ module ActiveRecord Relation.create(klass, table, predicate_builder) end - def predicate_builder(table) - PredicateBuilder.new(TableMetadata.new(klass, table)) - end - protected def actual_source_reflection # FIXME: this is a horrible name self end private + def predicate_builder(table) + PredicateBuilder.new(TableMetadata.new(klass, table)) + end def join_pk(_) foreign_key |