mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
almost fisted
This commit is contained in:
@@ -679,16 +679,12 @@ module ActiveRecord #:nodoc:
|
|||||||
|
|
||||||
# Returns an array of column objects for the table associated with this class.
|
# Returns an array of column objects for the table associated with this class.
|
||||||
def columns
|
def columns
|
||||||
@@columns[table_name] ||= connection.columns(
|
connection_pool.columns[table_name]
|
||||||
table_name, "#{name} Columns"
|
|
||||||
).tap { |columns|
|
|
||||||
columns.each { |column| column.primary = column.name == primary_key }
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash of column objects for the table associated with this class.
|
# Returns a hash of column objects for the table associated with this class.
|
||||||
def columns_hash
|
def columns_hash
|
||||||
@@columns_hash[table_name] ||= Hash[columns.map { |column| [column.name, column] }]
|
connection_pool.columns_hash[table_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of column names as strings.
|
# Returns an array of column names as strings.
|
||||||
@@ -745,21 +741,14 @@ module ActiveRecord #:nodoc:
|
|||||||
def reset_column_information
|
def reset_column_information
|
||||||
connection.clear_cache!
|
connection.clear_cache!
|
||||||
undefine_attribute_methods
|
undefine_attribute_methods
|
||||||
reset_column_cache
|
connection_pool.clear_table_cache!(table_name) if table_exists?
|
||||||
|
|
||||||
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
|
@column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
|
||||||
@arel_engine = @relation = nil
|
@arel_engine = @relation = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_cache! # :nodoc:
|
def clear_cache! # :nodoc:
|
||||||
@@columns.clear
|
connection_pool.clear_cache!
|
||||||
@@columns_hash.clear
|
|
||||||
@@arel_tables.clear
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset_column_cache # :nodoc:
|
|
||||||
@@columns.delete table_name
|
|
||||||
@@columns_hash.delete table_name
|
|
||||||
@@arel_tables.delete table_name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def attribute_method?(attribute)
|
def attribute_method?(attribute)
|
||||||
@@ -858,7 +847,7 @@ module ActiveRecord #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def arel_table
|
def arel_table
|
||||||
@@arel_tables[table_name] ||= Arel::Table.new(table_name, arel_engine)
|
Arel::Table.new(table_name, arel_engine)
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel_engine
|
def arel_engine
|
||||||
@@ -1406,9 +1395,6 @@ MSG
|
|||||||
quoted_value
|
quoted_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@columns_hash = {}
|
|
||||||
@@columns = {}
|
|
||||||
@@arel_tables = {}
|
|
||||||
|
|
||||||
public
|
public
|
||||||
# New objects can be instantiated as either empty (pass no construction parameter) or pre-set with
|
# New objects can be instantiated as either empty (pass no construction parameter) or pre-set with
|
||||||
|
|||||||
@@ -125,6 +125,13 @@ module ActiveRecord
|
|||||||
@primary_keys.clear
|
@primary_keys.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clear out internal caches for table with +table_name+
|
||||||
|
def clear_table_cache!(table_name)
|
||||||
|
@columns.delete table_name
|
||||||
|
@columns_hash.delete table_name
|
||||||
|
@primary_keys.delete table_name
|
||||||
|
end
|
||||||
|
|
||||||
# Retrieve the connection associated with the current thread, or call
|
# Retrieve the connection associated with the current thread, or call
|
||||||
# #checkout to obtain one if necessary.
|
# #checkout to obtain one if necessary.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -59,12 +59,12 @@ module ActiveRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def drop_table!
|
def drop_table!
|
||||||
reset_column_cache
|
connection_pool.clear_table_cache!(table_name)
|
||||||
connection.drop_table table_name
|
connection.drop_table table_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_table!
|
def create_table!
|
||||||
reset_column_cache
|
connection_pool.clear_table_cache!(table_name)
|
||||||
connection.create_table(table_name) do |t|
|
connection.create_table(table_name) do |t|
|
||||||
t.string session_id_column, :limit => 255
|
t.string session_id_column, :limit => 255
|
||||||
t.text data_column_name
|
t.text data_column_name
|
||||||
|
|||||||
@@ -757,10 +757,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
|
|||||||
david = Developer.find(1)
|
david = Developer.find(1)
|
||||||
# clear cache possibly created by other tests
|
# clear cache possibly created by other tests
|
||||||
david.projects.reset_column_information
|
david.projects.reset_column_information
|
||||||
assert_queries(0) { david.projects.columns; david.projects.columns }
|
assert_queries(1) { david.projects.columns; david.projects.columns }
|
||||||
# and again to verify that reset_column_information clears the cache correctly
|
# and again to verify that reset_column_information clears the cache correctly
|
||||||
david.projects.reset_column_information
|
david.projects.reset_column_information
|
||||||
assert_queries(0) { david.projects.columns; david.projects.columns }
|
assert_queries(1) { david.projects.columns; david.projects.columns }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attributes_are_being_set_when_initialized_from_habm_association_with_where_clause
|
def test_attributes_are_being_set_when_initialized_from_habm_association_with_where_clause
|
||||||
|
|||||||
Reference in New Issue
Block a user