Class: ActiveRecord::Associations::JoinDependency::Aliases

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/associations/join_dependency.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Column, Table

Instance Method Summary collapse

Constructor Details

#initialize(tables) ⇒ Aliases

Returns a new instance of Aliases.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_record/associations/join_dependency.rb', line 8

def initialize(tables)
  @tables = tables
  @alias_cache = tables.each_with_object({}) { |table,h|
    h[table.node] = table.columns.each_with_object({}) { |column,i|
      i[column.name] = column.alias
    }
  }
  @name_and_alias_cache = tables.each_with_object({}) { |table,h|
    h[table.node] = table.columns.map { |column|
      [column.name, column.alias]
    }
  }
end

Instance Method Details

#column_alias(node, column) ⇒ Object



31
32
33
# File 'lib/active_record/associations/join_dependency.rb', line 31

def column_alias(node, column)
  @alias_cache[node][column]
end

#column_aliases(node) ⇒ Object

An array of [column_name, alias] pairs for the table



27
28
29
# File 'lib/active_record/associations/join_dependency.rb', line 27

def column_aliases(node)
  @name_and_alias_cache[node]
end

#columnsObject



22
23
24
# File 'lib/active_record/associations/join_dependency.rb', line 22

def columns
  @tables.flat_map { |t| t.column_aliases }
end