1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use ARel rather than generate SQL strings

This commit is contained in:
Aaron Patterson 2010-11-24 13:40:23 -08:00
parent afe51afcc6
commit cdf6cf01cb
2 changed files with 4 additions and 3 deletions

View file

@ -33,10 +33,11 @@ module ActiveRecord
join_parts.first
end
def columns(connection)
def columns
join_parts.collect { |join_part|
table = Arel::Nodes::TableAlias.new join_part.aliased_table_name, nil
join_part.column_names_with_alias.collect{ |column_name, aliased_name|
"#{connection.quote_table_name join_part.aliased_table_name}.#{connection.quote_column_name column_name} AS #{aliased_name}"
table[column_name].as aliased_name
}
}.flatten
end

View file

@ -202,7 +202,7 @@ module ActiveRecord
end
def construct_relation_for_association_find(join_dependency)
relation = except(:includes, :eager_load, :preload, :select).select(join_dependency.columns(connection))
relation = except(:includes, :eager_load, :preload, :select).select(join_dependency.columns)
apply_join_dependency(relation, join_dependency)
end