diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute/user_provided_default.rb | 15 | ||||
-rw-r--r-- | activerecord/lib/active_record/attributes.rb | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute/user_provided_default.rb b/activerecord/lib/active_record/attribute/user_provided_default.rb index 29d37ac689..e0bee8c17e 100644 --- a/activerecord/lib/active_record/attribute/user_provided_default.rb +++ b/activerecord/lib/active_record/attribute/user_provided_default.rb @@ -3,8 +3,9 @@ require 'active_record/attribute' module ActiveRecord class Attribute # :nodoc: class UserProvidedDefault < FromUser - def initialize(name, value, type) + def initialize(name, value, type, database_default) super(name, value, type) + @database_default = database_default end def type_cast(value) @@ -14,6 +15,18 @@ module ActiveRecord super end end + + def changed_in_place_from?(old_value) + super || changed_from?(database_default.value) + end + + def with_type(type) + self.class.new(name, value_before_type_cast, type, database_default) + end + + protected + + attr_reader :database_default end end end diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index e574aebd6c..c89099589e 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -242,6 +242,7 @@ module ActiveRecord name, value, type, + _default_attributes[name], ) else default_attribute = Attribute.from_database(name, value, type) |