aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/model_schema.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r--activerecord/lib/active_record/model_schema.rb38
1 files changed, 14 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index 9e1afd32e6..ffd30eb87d 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -219,39 +219,33 @@ module ActiveRecord
connection.schema_cache.table_exists?(table_name)
end
- def column_types # :nodoc:
- @column_types ||= decorate_types(build_types_hash)
- end
-
- def type_for_attribute(attr_name) # :nodoc:
- column_types.fetch(attr_name) { Type::Value.new }
+ def attributes_builder # :nodoc:
+ @attributes_builder ||= AttributeSet::Builder.new(column_types)
end
- 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|
- types[name] = AttributeMethods::TimeZoneConversion::Type.new(types[name])
+ def column_types # :nodoc:
+ @column_types ||= Hash.new(Type::Value.new).tap do |column_types|
+ columns.each { |column| column_types[column.name] = column.cast_type }
end
+ end
- types
+ def type_for_attribute(attr_name) # :nodoc:
+ column_types[attr_name]
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
- @column_defaults ||= Hash[columns.map { |c| [c.name, c.default] }]
+ @column_defaults ||= Hash[columns_hash.map { |name, column|
+ [name, column.type_cast_from_database(column.default)]
+ }]
end
# Returns a hash where the keys are the column names and the values
# are the default values suitable for use in `@raw_attriubtes`
def raw_column_defaults # :nodoc:
- @raw_column_defauts ||= Hash[column_defaults.map { |name, default|
- [name, columns_hash[name].type_cast_for_database(default)]
+ @raw_column_defaults ||= Hash[columns_hash.map { |name, column|
+ [name, column.default]
}]
end
@@ -299,7 +293,7 @@ module ActiveRecord
@arel_engine = nil
@column_defaults = nil
- @raw_column_defauts = nil
+ @raw_column_defaults = nil
@column_names = nil
@column_types = nil
@content_columns = nil
@@ -335,10 +329,6 @@ module ActiveRecord
base.table_name
end
end
-
- def build_types_hash
- Hash[columns.map { |column| [column.name, column.cast_type] }]
- end
end
end
end