aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/model_schema.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-09 16:13:48 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-09 16:13:48 -0300
commitddb0b4a474de99fa8474e2111a05dd4bba7c6f0e (patch)
tree504334562aa90a23f286616fcb36604628182e06 /activerecord/lib/active_record/model_schema.rb
parent19f1cfbb03f8230f5d30cc91c41c3f719813da9d (diff)
parentc93dbfef36c9b095121650beec2362de42d6b715 (diff)
downloadrails-ddb0b4a474de99fa8474e2111a05dd4bba7c6f0e.tar.gz
rails-ddb0b4a474de99fa8474e2111a05dd4bba7c6f0e.tar.bz2
rails-ddb0b4a474de99fa8474e2111a05dd4bba7c6f0e.zip
Merge pull request #15591 from sgrif/sg-rm-write-attribute
Make `_before_type_cast` actually be before type cast
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r--activerecord/lib/active_record/model_schema.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index baf2b5fbf8..f96f77f696 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -51,6 +51,8 @@ module ActiveRecord
self.pluralize_table_names = true
self.inheritance_column = 'type'
+
+ delegate :type_for_attribute, to: :class
end
module ClassMethods
@@ -221,6 +223,10 @@ module ActiveRecord
@column_types ||= decorate_columns(columns_hash.dup)
end
+ def type_for_attribute(attr_name) # :nodoc:
+ column_types.fetch(attr_name) { column_for_attribute(attr_name) }
+ end
+
def decorate_columns(columns_hash) # :nodoc:
return if columns_hash.empty?
@@ -245,7 +251,7 @@ module ActiveRecord
# 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)]
+ [name, columns_hash[name].type_cast_for_database(default)]
}]
end