aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/visitors/to_sql.rb31
-rw-r--r--test/support/fake_record.rb13
-rw-r--r--test/test_select_manager.rb4
3 files changed, 19 insertions, 29 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 61f68a8c09..70e10a5e0f 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -11,14 +11,6 @@ module Arel
@last_column = nil
@quoted_tables = {}
@quoted_columns = {}
- @column_cache = Hash.new { |h,pool|
- h[pool] = Hash.new { |conn_h,column|
- conn_h[column] = {}
- }
- }
- @table_exists = Hash.new { |h,pool|
- h[pool] = {}
- }
end
def accept object
@@ -91,37 +83,20 @@ key on UpdateManager using UpdateManager#key=
end
def table_exists? name
- return true if table_exists.key? name
-
- @connection.tables.each do |table|
- table_exists[table] = true
- end
-
- table_exists.key? name
- end
-
- def table_exists
- @table_exists[@pool]
+ @pool.table_exists? name
end
def column_for attr
- name = attr.name.to_sym
+ name = attr.name.to_s
table = attr.relation.name
return nil unless table_exists? table
- # If we don't have this column cached, get a list of columns and
- # cache them for this table
- unless column_cache.key? table
- columns = @connection.columns(table, "#{table}(#{name}) Columns")
- column_cache[table] = Hash[columns.map { |c| [c.name.to_sym, c] }]
- end
-
column_cache[table][name]
end
def column_cache
- @column_cache[@pool]
+ @pool.columns_hash
end
def visit_Arel_Nodes_Values o
diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb
index 376ed40f2d..54f73489c9 100644
--- a/test/support/fake_record.rb
+++ b/test/support/fake_record.rb
@@ -3,7 +3,7 @@ module FakeRecord
end
class Connection
- attr_reader :tables
+ attr_reader :tables, :columns_hash
def initialize
@tables = %w{ users photos developers }
@@ -15,6 +15,9 @@ module FakeRecord
Column.new('created_at', :date),
]
}
+ @columns_hash = {
+ 'users' => Hash[@columns['users'].map { |x| [x.name, x] }]
+ }
@primary_keys = {
'users' => 'id'
}
@@ -75,6 +78,14 @@ module FakeRecord
def with_connection
yield connection
end
+
+ def table_exists? name
+ connection.tables.include? name.to_s
+ end
+
+ def columns_hash
+ connection.columns_hash
+ end
end
class Base
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index 3ffdbe2e23..3b5ded8389 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -30,6 +30,10 @@ module Arel
@engine.connection.columns table, message
end
+ def columns_hash
+ @engine.connection.columns_hash
+ end
+
def table_exists? name
@engine.connection.table_exists? name
end