module ActiveRecord::Associations::JoinHelper

Private Instance Methods

construct_tables() click to toggle source

AR > 3.0 and < 4.2 (%%% maybe only < 4.1?) uses construct_tables like this:

# File lib/duty_free.rb, line 401
def construct_tables
  tables = []
  chain.each do |reflection|
    tables << alias_tracker.aliased_table_for(
      table_name_for(reflection),
      table_alias_for(reflection, reflection != self.reflection)
    ).tap do |x|
      x = x.left if x.is_a?(Arel::Nodes::TableAlias)
      x.instance_variable_set(:@_arel_table_type, reflection.chain.find { |c| c.table_name == x.name }.klass)
    end

    next unless reflection.source_macro == :has_and_belongs_to_many

    tables << alias_tracker.aliased_table_for(
      (reflection.source_reflection || reflection).join_table,
      table_alias_for(reflection, true)
    )
  end
  tables
end