From 0fddc3c1c07e83249e4b6ff1ed5f6b7f74e41c1f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Feb 2014 12:13:24 -0800 Subject: JoinHelper is never reused, so there is no need to separate --- .../associations/association_scope.rb | 30 +++++++++++++++--- .../lib/active_record/associations/join_helper.rb | 36 ---------------------- 2 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 activerecord/lib/active_record/associations/join_helper.rb (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 5a0ba9e6b1..69deb5f2e0 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -1,10 +1,6 @@ -require 'active_record/associations/join_helper' - module ActiveRecord module Associations class AssociationScope #:nodoc: - include JoinHelper - attr_reader :association, :alias_tracker delegate :klass, :owner, :reflection, :interpolate, :to => :association @@ -21,8 +17,32 @@ module ActiveRecord add_constraints(scope) end + def join_type + Arel::Nodes::InnerJoin + end + private + def construct_tables + chain.map do |reflection| + alias_tracker.aliased_table_for( + table_name_for(reflection), + table_alias_for(reflection, reflection != self.reflection) + ) + end + end + + + def table_alias_for(reflection, join = false) + name = "#{reflection.plural_name}_#{alias_suffix}" + name << "_join" if join + name + end + + def join(table, constraint) + table.create_join(table, table.create_on(constraint), join_type) + end + def column_for(table_name, column_name) columns = alias_tracker.connection.schema_cache.columns_hash(table_name) columns[column_name] @@ -115,7 +135,7 @@ module ActiveRecord # the owner klass.table_name else - super + reflection.table_name end end diff --git a/activerecord/lib/active_record/associations/join_helper.rb b/activerecord/lib/active_record/associations/join_helper.rb deleted file mode 100644 index 3471936b9f..0000000000 --- a/activerecord/lib/active_record/associations/join_helper.rb +++ /dev/null @@ -1,36 +0,0 @@ -module ActiveRecord - module Associations - # Helper class module which gets mixed into JoinDependency::JoinAssociation and AssociationScope - module JoinHelper #:nodoc: - - def join_type - Arel::Nodes::InnerJoin - end - - private - - def construct_tables - chain.map do |reflection| - alias_tracker.aliased_table_for( - table_name_for(reflection), - table_alias_for(reflection, reflection != self.reflection) - ) - end - end - - def table_name_for(reflection) - reflection.table_name - end - - def table_alias_for(reflection, join = false) - name = "#{reflection.plural_name}_#{alias_suffix}" - name << "_join" if join - name - end - - def join(table, constraint) - table.create_join(table, table.create_on(constraint), join_type) - end - end - end -end -- cgit v1.2.3