diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency/join_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 29 |
1 files changed, 8 insertions, 21 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 3af613d2d1..a6a7b447cc 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -4,43 +4,30 @@ module ActiveRecord module Associations class JoinDependency # :nodoc: class JoinAssociation < JoinPart # :nodoc: - include JoinHelper - # The reflection of the association represented attr_reader :reflection # What type of join will be generated, either Arel::InnerJoin (default) or Arel::OuterJoin attr_accessor :join_type - # These implement abstract methods from the superclass - attr_reader :aliased_prefix - - attr_reader :tables - attr_reader :alias_tracker + attr_accessor :tables - delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection - - def initialize(reflection, index, parent, join_type, alias_tracker) - super(reflection.klass, parent) + def initialize(reflection, join_type) + super(reflection.klass) @reflection = reflection - @alias_tracker = alias_tracker @join_type = join_type - @aliased_prefix = "t#{ index }" - @tables = construct_tables.reverse + @tables = nil end - def parent_table_name; parent.table_name; end - alias :alias_suffix :parent_table_name - def match?(other) return true if self == other super && reflection == other.reflection end - def join_constraints + def join_constraints(parent, tables) joins = [] - tables = @tables.dup + tables = tables.dup foreign_table = parent.table foreign_klass = parent.base_klass @@ -49,7 +36,7 @@ module ActiveRecord # The chain starts with the target table, but we want to end with it here (makes # more sense in this context), so we reverse - chain.reverse_each do |reflection| + reflection.chain.reverse_each do |reflection| table = tables.shift klass = reflection.klass @@ -88,7 +75,7 @@ module ActiveRecord constraint = constraint.and rel.arel.constraints end - joins << join(table, constraint) + joins << table.create_join(table, table.create_on(constraint), join_type) # The current table in this iteration becomes the foreign table in the next foreign_table, foreign_klass = table, klass |