aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-11 07:54:39 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-11 07:54:39 -0600
commit09dd29e4f775ef398bb9031dddebe6b84a7155b6 (patch)
treef3d5af18fc14e75b5754aeaf0c39dfd1ac249b76 /activerecord
parentef4e0787d757c40a23bee4558db4d2525ca8cbef (diff)
downloadrails-09dd29e4f775ef398bb9031dddebe6b84a7155b6.tar.gz
rails-09dd29e4f775ef398bb9031dddebe6b84a7155b6.tar.bz2
rails-09dd29e4f775ef398bb9031dddebe6b84a7155b6.zip
Ensure `column_types` returns a type object, and not a column
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/model_schema.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index f96f77f696..9e1afd32e6 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -220,25 +220,25 @@ module ActiveRecord
end
def column_types # :nodoc:
- @column_types ||= decorate_columns(columns_hash.dup)
+ @column_types ||= decorate_types(build_types_hash)
end
def type_for_attribute(attr_name) # :nodoc:
- column_types.fetch(attr_name) { column_for_attribute(attr_name) }
+ column_types.fetch(attr_name) { Type::Value.new }
end
- def decorate_columns(columns_hash) # :nodoc:
- return if columns_hash.empty?
+ def decorate_types(types) # :nodoc:
+ return if types.empty?
@time_zone_column_names ||= self.columns_hash.find_all do |name, col|
create_time_zone_conversion_attribute?(name, col)
end.map!(&:first)
@time_zone_column_names.each do |name|
- columns_hash[name] = AttributeMethods::TimeZoneConversion::Type.new(columns_hash[name])
+ types[name] = AttributeMethods::TimeZoneConversion::Type.new(types[name])
end
- columns_hash
+ types
end
# Returns a hash where the keys are column names and the values are
@@ -335,6 +335,10 @@ module ActiveRecord
base.table_name
end
end
+
+ def build_types_hash
+ Hash[columns.map { |column| [column.name, column.cast_type] }]
+ end
end
end
end