diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-13 12:13:24 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-13 12:13:41 -0800 |
commit | 0fddc3c1c07e83249e4b6ff1ed5f6b7f74e41c1f (patch) | |
tree | 3ea9edd2595853d23a88fb48e1d16e4f7afdc931 | |
parent | bfc34fc0050ce61650701676dd45553aa82214c0 (diff) | |
download | rails-0fddc3c1c07e83249e4b6ff1ed5f6b7f74e41c1f.tar.gz rails-0fddc3c1c07e83249e4b6ff1ed5f6b7f74e41c1f.tar.bz2 rails-0fddc3c1c07e83249e4b6ff1ed5f6b7f74e41c1f.zip |
JoinHelper is never reused, so there is no need to separate
3 files changed, 25 insertions, 42 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index b5e21cbede..142d21ce92 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -130,7 +130,6 @@ module ActiveRecord autoload :JoinDependency, 'active_record/associations/join_dependency' autoload :AssociationScope, 'active_record/associations/association_scope' autoload :AliasTracker, 'active_record/associations/alias_tracker' - autoload :JoinHelper, 'active_record/associations/join_helper' end # Clears out the association cache. 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 |