From 00b62ab73bef05126fdfb72291beee60898c4f8e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 7 Feb 2012 11:51:30 -0800 Subject: moving column types to an ivar on the result --- activerecord/lib/active_record/attribute_methods/read.rb | 6 +++++- activerecord/lib/active_record/result.rb | 13 +++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 66f4b0b6c6..a52d36aad8 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -125,7 +125,11 @@ module ActiveRecord # Returns the value of the attribute identified by attr_name after it has been typecast (for example, # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). def read_attribute(attr_name) - self.class.type_cast_attribute(attr_name, @attributes, @attributes_cache) + if @columns_hash.key? attr_name + @columns_hash[attr_name].type_cast @attributes[attr_name] + else + self.class.type_cast_attribute(attr_name, @attributes, @attributes_cache) + end end private diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index 4eb2cf3a72..fb4b89b87b 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -8,12 +8,13 @@ module ActiveRecord class Result include Enumerable - attr_reader :columns, :rows + attr_reader :columns, :rows, :column_types def initialize(columns, rows) - @columns = columns - @rows = rows - @hash_rows = nil + @columns = columns + @rows = rows + @hash_rows = nil + @column_types = {} end def each @@ -49,10 +50,6 @@ module ActiveRecord @hash_rows = nil end - def column_types - {} - end - private def hash_rows @hash_rows ||= @rows.map { |row| -- cgit v1.2.3