Class: ActiveRecord::HierarchicalQuery::JoinBuilder::SubqueryAlias

Inherits:
Arel::Nodes::As
  • Object
show all
Defined in:
lib/active_record/hierarchical_query/join_builder.rb

Overview

This node is required to support joins to aliased Arel nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subquery, alias_node) ⇒ SubqueryAlias

Returns a new instance of SubqueryAlias.

Raises:

  • (RuntimeError)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_record/hierarchical_query/join_builder.rb', line 98

def initialize(subquery, alias_node)
  super

  @table_name = alias_node.try :name

  return unless alias_node.respond_to? :left

  aliased_name = alias_node.left.relation.name
  return if @table_name == aliased_name

  # Defensive coding; this shouldn't happen unless the
  # Rails team does a change to how Arel works.
  message = "Unexpected alias name mismatch"
  raise RuntimeError, message
end

Instance Attribute Details

#table_nameObject (readonly) Also known as: name

Returns the value of attribute table_name.



92
93
94
# File 'lib/active_record/hierarchical_query/join_builder.rb', line 92

def table_name
  @table_name
end