mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure column_types
returns a type object, and not a column
This commit is contained in:
parent
ef4e0787d7
commit
09dd29e4f7
1 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue