From a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Oct 2013 18:18:56 -0700 Subject: let the Table class build the ARel alias nodes --- .../lib/active_record/associations/join_dependency.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 94255fc74f..ab62131490 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -91,14 +91,19 @@ module ActiveRecord @tables.flat_map { |t| t.columns } end - Table = Struct.new(:table, :columns) + class Table < Struct.new(:table, :columns) + def columns + super.map { |column| table[column.name].as Arel.sql column.alias } + end + end + Column = Struct.new(:name, :alias) end def aliases - Aliases.new join_root.map { |join_part| + Aliases.new join_root.each_with_index.map { |join_part,i| table = join_part.aliased_table - columns = join_part.column_names_with_alias.collect{ |column_name, aliased_name| - table[column_name].as Arel.sql(aliased_name) + 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) } -- cgit v1.2.3