aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-14 18:18:56 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-14 18:18:56 -0700
commita3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b (patch)
tree783a3838b40df81ac7abe2a74875b00198fb6a9d
parentfc61df5a62df7f873122d70827c1a7e37c2aa22f (diff)
downloadrails-a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b.tar.gz
rails-a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b.tar.bz2
rails-a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b.zip
let the Table class build the ARel alias nodes
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb13
1 files 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)
}