diff options
author | Matthew Erhard <merhard@gmail.com> | 2016-05-11 13:09:34 -0400 |
---|---|---|
committer | Matthew Erhard <merhard@gmail.com> | 2016-05-11 13:21:01 -0400 |
commit | 556e530da41dce5ae8070e8e075390bbedb949c0 (patch) | |
tree | 356ccae535f0a627119a11a8e1cd23f6be829a13 /activerecord/lib/active_record | |
parent | 59d252196b36f6afaafd231756d69ea21537cf5d (diff) | |
download | rails-556e530da41dce5ae8070e8e075390bbedb949c0.tar.gz rails-556e530da41dce5ae8070e8e075390bbedb949c0.tar.bz2 rails-556e530da41dce5ae8070e8e075390bbedb949c0.zip |
Define ActiveRecord::Attribute::Null#type_cast
Using ActiveRecord::Base.attribute to declare an attribute with a default value on a model where the attribute is not backed by the database would raise a NotImplementedError when model.save is called.
The error originates from https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L84.
This is called from https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L46 on an ActiveRecord::Attribute::Null object.
This commit corrects the behavior by implementing ActiveRecord::Attribute::Null#type_cast.
With ActiveRecord::Attribute::Null#type_cast defined, ActiveRecord::Attribute::Null#value (https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L173..L175) can be replaced with its super method (https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L36..L40).
fixes #24979
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/attribute.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb index 3c4c8f10ec..24231dc9e1 100644 --- a/activerecord/lib/active_record/attribute.rb +++ b/activerecord/lib/active_record/attribute.rb @@ -170,7 +170,7 @@ module ActiveRecord super(name, nil, Type::Value.new) end - def value + def type_cast(*) nil end |