diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-09 11:23:19 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-09 11:23:19 -0800 |
commit | 5b82f50feff3c80cbe7a7ae33b078baa1515150a (patch) | |
tree | 5711db729a9f9b367de1625ad1e184a5e9738810 | |
parent | 007965a6513f2631465cf8477846daf9532dafc4 (diff) | |
download | rails-5b82f50feff3c80cbe7a7ae33b078baa1515150a.tar.gz rails-5b82f50feff3c80cbe7a7ae33b078baa1515150a.tar.bz2 rails-5b82f50feff3c80cbe7a7ae33b078baa1515150a.zip |
Use `table_exists?` from the schema cache.
4 files changed, 7 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 58d23d2f78..ba75dc6d09 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -762,7 +762,7 @@ module ActiveRecord #:nodoc: # Indicates whether the table associated with this class exists def table_exists? - connection.table_exists?(table_name) + connection.schema_cache.table_exists?(table_name) end # Returns an array of column objects for the table associated with this class. diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index b14b37ce89..bee03abd44 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -42,10 +42,7 @@ module ActiveRecord def table_exists?(name) return @tables[name] if @tables.key? name - connection.tables.each { |table| @tables[table] = true } - @tables[name] = connection.table_exists?(name) if !@tables.key?(name) - - @tables[name] + @tables[name] = connection.table_exists?(name) end # Clears out internal caches: @@ -66,6 +63,7 @@ module ActiveRecord @columns_hash.delete table_name @column_defaults.delete table_name @primary_keys.delete table_name + @tables.delete table_name end end end diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index b49510b202..745f7132e7 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -825,12 +825,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase # clear cache possibly created by other tests david.projects.reset_column_information - # One query for columns, one for primary key - assert_queries(2) { david.projects.columns; david.projects.columns } + # One query for columns, one for primary key, one for table existence + assert_queries(3) { david.projects.columns; david.projects.columns } ## and again to verify that reset_column_information clears the cache correctly david.projects.reset_column_information - assert_queries(2) { david.projects.columns; david.projects.columns } + assert_queries(3) { david.projects.columns; david.projects.columns } end def test_attributes_are_being_set_when_initialized_from_habm_association_with_where_clause diff --git a/activerecord/test/cases/session_store/session_test.rb b/activerecord/test/cases/session_store/session_test.rb index 258cee7aba..c206e3de4a 100644 --- a/activerecord/test/cases/session_store/session_test.rb +++ b/activerecord/test/cases/session_store/session_test.rb @@ -9,6 +9,7 @@ module ActiveRecord def setup super + ActiveRecord::Base.connection.schema_cache.clear! Session.drop_table! if Session.table_exists? end |