Skip to content

Commit

Permalink
JoinHelper is never reused, so there is no need to separate
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 13, 2014
1 parent bfc34fc commit 0fddc3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 42 deletions.
1 change: 0 additions & 1 deletion activerecord/lib/active_record/associations.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ module Builder #:nodoc:
autoload :JoinDependency, 'active_record/associations/join_dependency' autoload :JoinDependency, 'active_record/associations/join_dependency'
autoload :AssociationScope, 'active_record/associations/association_scope' autoload :AssociationScope, 'active_record/associations/association_scope'
autoload :AliasTracker, 'active_record/associations/alias_tracker' autoload :AliasTracker, 'active_record/associations/alias_tracker'
autoload :JoinHelper, 'active_record/associations/join_helper'
end end


# Clears out the association cache. # Clears out the association cache.
Expand Down
30 changes: 25 additions & 5 deletions activerecord/lib/active_record/associations/association_scope.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'active_record/associations/join_helper'

module ActiveRecord module ActiveRecord
module Associations module Associations
class AssociationScope #:nodoc: class AssociationScope #:nodoc:
include JoinHelper

attr_reader :association, :alias_tracker attr_reader :association, :alias_tracker


delegate :klass, :owner, :reflection, :interpolate, :to => :association delegate :klass, :owner, :reflection, :interpolate, :to => :association
Expand All @@ -21,8 +17,32 @@ def scope
add_constraints(scope) add_constraints(scope)
end end


def join_type
Arel::Nodes::InnerJoin
end

private 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) def column_for(table_name, column_name)
columns = alias_tracker.connection.schema_cache.columns_hash(table_name) columns = alias_tracker.connection.schema_cache.columns_hash(table_name)
columns[column_name] columns[column_name]
Expand Down Expand Up @@ -115,7 +135,7 @@ def table_name_for(reflection)
# the owner # the owner
klass.table_name klass.table_name
else else
super reflection.table_name
end end
end end


Expand Down
36 changes: 0 additions & 36 deletions activerecord/lib/active_record/associations/join_helper.rb

This file was deleted.

0 comments on commit 0fddc3c

Please sign in to comment.