aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_scope.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/association_scope.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb30
1 files changed, 25 insertions, 5 deletions
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