diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-08-26 08:43:04 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-08-27 07:13:42 -0600 |
commit | 990322b298c41b65be01238c56e2d7ff0dd76cb6 (patch) | |
tree | 7a648c78da29603831752316ac150442b153c70e /activerecord/lib | |
parent | 49b27dba286b0f9536f1f0e366a431b762bf7885 (diff) | |
download | rails-990322b298c41b65be01238c56e2d7ff0dd76cb6.tar.gz rails-990322b298c41b65be01238c56e2d7ff0dd76cb6.tar.bz2 rails-990322b298c41b65be01238c56e2d7ff0dd76cb6.zip |
Correctly detect mutation on serialized columns mapping to binary
Fixes #16701
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/type/binary.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/serialized.rb | 5 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/binary.rb b/activerecord/lib/active_record/type/binary.rb index d29ff4e494..005a48ef0d 100644 --- a/activerecord/lib/active_record/type/binary.rb +++ b/activerecord/lib/active_record/type/binary.rb @@ -22,6 +22,11 @@ module ActiveRecord Data.new(super) end + def changed_in_place?(raw_old_value, value) + old_value = type_cast_from_database(raw_old_value) + old_value != value + end + class Data # :nodoc: def initialize(value) @value = value.to_s @@ -30,10 +35,15 @@ module ActiveRecord def to_s @value end + alias_method :to_str, :to_s def hex @value.unpack('H*')[0] end + + def ==(other) + other == to_s || super + end end end end diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index abeea769c4..5b512433b0 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -26,6 +26,11 @@ module ActiveRecord end end + def changed_in_place?(raw_old_value, value) + return false if value.nil? + subtype.changed_in_place?(raw_old_value, coder.dump(value)) + end + def accessor ActiveRecord::Store::IndifferentHashAccessor end |