Permalink
Browse files

let the Table class build the ARel alias nodes

  • Loading branch information...
1 parent fc61df5 commit a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b @tenderlove tenderlove committed Oct 15, 2013
Showing with 9 additions and 4 deletions.
  1. +9 −4 activerecord/lib/active_record/associations/join_dependency.rb
@@ -91,14 +91,19 @@ def columns
@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)
}

0 comments on commit a3a6313

Please sign in to comment.