From dbc1f65244ac0b75f746ea91289f2e36ced435a6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Dec 2010 08:55:14 -0800 Subject: starting the column cache --- lib/arel/visitors/to_sql.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/arel') diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 9694ed4cb8..b8a991b965 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -10,6 +10,7 @@ module Arel @last_column = nil @quoted_tables = {} @quoted_columns = {} + @column_cache = {} end def accept object @@ -66,9 +67,17 @@ module Arel o.alias ? " AS #{visit o.alias}" : ''}" end + def column_for relation, name + name = name.to_s + table = relation.name + + columns = @connection.columns(table, "#{table} Columns") + columns.find { |col| col.name.to_s == name } + end + def visit_Arel_Nodes_Values o "VALUES (#{o.expressions.zip(o.columns).map { |value, attr| - quote(value, attr && attr.column) + quote(value, attr && column_for(attr.relation, attr.name)) }.join ', '})" end -- cgit v1.2.3