From a53c2beac42e0fea5dab9a334a066911beeba976 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Oct 2013 18:26:34 -0700 Subject: move alias building to the table node --- .../lib/active_record/associations/join_dependency.rb | 12 ++++++++---- .../active_record/associations/join_dependency/join_part.rb | 4 ---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index ab62131490..2a558074d8 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -91,9 +91,14 @@ module ActiveRecord @tables.flat_map { |t| t.columns } end - class Table < Struct.new(:table, :columns) + class Table < Struct.new(:name, :alias, :columns) + def table + Arel::Nodes::TableAlias.new name, self.alias + end + def columns - super.map { |column| table[column.name].as Arel.sql column.alias } + t = table + super.map { |column| t[column.name].as Arel.sql column.alias } end end Column = Struct.new(:name, :alias) @@ -101,11 +106,10 @@ module ActiveRecord def aliases Aliases.new join_root.each_with_index.map { |join_part,i| - table = join_part.aliased_table columns = join_part.column_names.each_with_index.map { |column_name,j| Aliases::Column.new column_name, "t#{i}_r#{j}" } - Aliases::Table.new(table, columns) + Aliases::Table.new(join_part.table, join_part.aliased_table_name, columns) } end diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb index 632571e2fe..2c4111e5ed 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb @@ -36,10 +36,6 @@ module ActiveRecord children.each { |child| child.each(&block) } end - def aliased_table - Arel::Nodes::TableAlias.new table, aliased_table_name - end - # An Arel::Table for the active_record def table raise NotImplementedError -- cgit v1.2.3