Permalink
Browse files

store aliases in a better structure

  • Loading branch information...
1 parent 4bf10fc commit fc61df5a62df7f873122d70827c1a7e37c2aa22f @tenderlove tenderlove committed Oct 15, 2013
@@ -82,13 +82,26 @@ def join_constraints
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)
@@ -243,7 +243,9 @@ def raise_record_not_found_exception!(ids, result_size, expected_size) #:nodoc:
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?

0 comments on commit fc61df5

Please sign in to comment.