diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-14 18:26:34 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-14 18:26:34 -0700 |
commit | a53c2beac42e0fea5dab9a334a066911beeba976 (patch) | |
tree | 9a9143fbd35e3edf6e68cd35d7609739a3f985ca /activerecord/lib | |
parent | a3a6313c1b12b8b9c3a38ad8e07b9dd2344c433b (diff) | |
download | rails-a53c2beac42e0fea5dab9a334a066911beeba976.tar.gz rails-a53c2beac42e0fea5dab9a334a066911beeba976.tar.bz2 rails-a53c2beac42e0fea5dab9a334a066911beeba976.zip |
move alias building to the table node
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/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 |