diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-14 18:10:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-14 18:10:43 -0700 |
commit | fc61df5a62df7f873122d70827c1a7e37c2aa22f (patch) | |
tree | 53d52826e6ee9a647432a0a93075cbae701908ce /activerecord | |
parent | 4bf10fcdee37ca4f16e04e26b7720568b14b0e4b (diff) | |
download | rails-fc61df5a62df7f873122d70827c1a7e37c2aa22f.tar.gz rails-fc61df5a62df7f873122d70827c1a7e37c2aa22f.tar.bz2 rails-fc61df5a62df7f873122d70827c1a7e37c2aa22f.zip |
store aliases in a better structure
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 21 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 4 |
2 files changed, 20 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 4635601781..94255fc74f 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -82,13 +82,26 @@ module ActiveRecord make_joins join_root end - def columns - join_root.collect { |join_part| + class Aliases + def initialize(tables) + @tables = tables + end + + def columns + @tables.flat_map { |t| t.columns } + end + + Table = Struct.new(:table, :columns) + end + + def aliases + Aliases.new join_root.map { |join_part| table = join_part.aliased_table - join_part.column_names_with_alias.collect{ |column_name, aliased_name| + columns = join_part.column_names_with_alias.collect{ |column_name, aliased_name| table[column_name].as Arel.sql(aliased_name) } - }.flatten + Aliases::Table.new(table, columns) + } end def instantiate(result_set) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 92969cfb30..5e11ba0325 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -243,7 +243,9 @@ module ActiveRecord def find_with_associations join_dependency = construct_join_dependency relation = except :select - relation = relation.select(join_dependency.columns) + + aliases = join_dependency.aliases + relation = relation.select aliases.columns relation = apply_join_dependency(relation, join_dependency) if block_given? |