From d592ea3b02c7e0952b87b876ad92bd1b453543c8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Feb 2012 14:34:53 -0800 Subject: wrap and cache columns for typecasting --- activerecord/lib/active_record/model_schema.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/model_schema.rb') diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 61f82af0c3..5486e192e4 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -206,6 +206,14 @@ module ActiveRecord @columns_hash ||= Hash[columns.map { |c| [c.name, c] }] end + def column_types + @column_types ||= columns_hash.dup.tap { |x| + serialized_attributes.keys.each do |key| + x[key] = AttributeMethods::Serialization::Type.new(x[key]) + end + } + end + # Returns a hash where the keys are column names and the values are # default values when instantiating the AR object for this table. def column_defaults @@ -268,9 +276,16 @@ module ActiveRecord undefine_attribute_methods connection.schema_cache.clear_table_cache!(table_name) if table_exists? - @column_names = @content_columns = @column_defaults = @columns = @columns_hash = nil - @dynamic_methods_hash = @inheritance_column = nil - @arel_engine = @relation = nil + @arel_engine = nil + @column_defaults = nil + @column_names = nil + @columns = nil + @columns_hash = nil + @column_types = nil + @content_columns = nil + @dynamic_methods_hash = nil + @inheritance_column = nil + @relation = nil end def clear_cache! # :nodoc: -- cgit v1.2.3