Class: ActiveRecord::Associations::JoinDependency::Aliases
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::JoinDependency::Aliases
- Defined in:
- lib/active_record/associations/join_dependency.rb
Overview
:nodoc:
Defined Under Namespace
Instance Method Summary collapse
- #column_alias(node, column) ⇒ Object
-
#column_aliases(node) ⇒ Object
An array of [column_name, alias] pairs for the table.
- #columns ⇒ Object
-
#initialize(tables) ⇒ Aliases
constructor
A new instance of Aliases.
Constructor Details
#initialize(tables) ⇒ Aliases
Returns a new instance of Aliases.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record/associations/join_dependency.rb', line 10 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
33 34 35 |
# File 'lib/active_record/associations/join_dependency.rb', line 33 def column_alias(node, column) @alias_cache[node][column] end |
#column_aliases(node) ⇒ Object
An array of [column_name, alias] pairs for the table
29 30 31 |
# File 'lib/active_record/associations/join_dependency.rb', line 29 def column_aliases(node) @name_and_alias_cache[node] end |
#columns ⇒ Object
24 25 26 |
# File 'lib/active_record/associations/join_dependency.rb', line 24 def columns @tables.flat_map(&:column_aliases) end |