diff options
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 22 | ||||
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 2 |
2 files changed, 16 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 4475019e0e..b1754e61df 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -59,7 +59,7 @@ module ActiveRecord class ConnectionPool attr_accessor :automatic_reconnect attr_reader :spec, :connections - attr_reader :columns, :columns_hash, :primary_keys + attr_reader :columns, :columns_hash, :primary_keys, :tables # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification # object which describes database connection information (e.g. adapter, @@ -84,12 +84,7 @@ module ActiveRecord @connections = [] @checked_out = [] @automatic_reconnect = true - - @tables = Hash.new do |h, table_name| - with_connection do |conn| - h[table_name] = conn.table_exists?(table_name) - end - end + @tables = {} @columns = Hash.new do |h, table_name| h[table_name] = with_connection do |conn| @@ -113,11 +108,22 @@ module ActiveRecord @primary_keys = Hash.new do |h, table_name| h[table_name] = with_connection do |conn| - @tables[table_name] ? conn.primary_key(table_name) : 'id' + table_exists?(table_name) ? conn.primary_key(table_name) : 'id' end end end + # A cached lookup for table existence + def table_exists?(name) + return true if @tables.key? name + + with_connection do |conn| + conn.tables.each { |table| @tables[table] = true } + end + + @tables.key? name + end + # Clears out internal caches: # # * columns diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index e11f1009dc..3074648d59 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -851,6 +851,8 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_eager_loading_with_conditions_on_join_model_preloads + Author.columns + authors = assert_queries(2) do Author.find(:all, :include => :author_address, :joins => :comments, :conditions => "posts.title like 'Welcome%'") end |