diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-03 08:23:30 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-03 10:27:38 -0600 |
commit | ed559d4b00fbd7c6f86e75fd2d18a40e16b98281 (patch) | |
tree | 87cfc9cd37c31c4c53c2437915db4da8e8019c46 /activerecord/lib/active_record/model_schema.rb | |
parent | 098bb63ae4acc349826ab84b3e1dff985e38609c (diff) | |
download | rails-ed559d4b00fbd7c6f86e75fd2d18a40e16b98281.tar.gz rails-ed559d4b00fbd7c6f86e75fd2d18a40e16b98281.tar.bz2 rails-ed559d4b00fbd7c6f86e75fd2d18a40e16b98281.zip |
Keep column defaults in type cast form
The contract of `_field_changed?` assumes that the old value is always
type cast. That is not the case for the value in `Column#default` as
things are today. It appears there are other public methods that
assume that `Column#default` is type cast, as well. The reason for this
change originally was because the value gets put into `@raw_attributes`
in initialize. This reverts to the old behavior on `Column`, and updates
`initialize` to make sure that the values are in the right format.
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index f0ddf202c3..baf2b5fbf8 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -241,6 +241,14 @@ module ActiveRecord @column_defaults ||= Hash[columns.map { |c| [c.name, c.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_write(default)] + }] + end + # Returns an array of column names as strings. def column_names @column_names ||= columns.map { |column| column.name } @@ -285,6 +293,7 @@ module ActiveRecord @arel_engine = nil @column_defaults = nil + @raw_column_defauts = nil @column_names = nil @column_types = nil @content_columns = nil |