From c587b636648394e33292ba8ba47d22bdad7446c3 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 2 Jun 2016 11:32:05 -0400 Subject: Ensure that records with unselected fields can be updated As part of refactoring mutation detection to be more performant, we introduced the concept of `original_value` to `Attribute`. This was not overridden in `Attribute::Uninitialized` however, so assigning ot an uninitialized value and calling `.changed?` would raise `NotImplementedError`. We are using a sentinel value rather than checking the result of `original_attribute.initialized?` in `changed?` because `original_value` might go through more than one node in the tree. Fixes #25228 --- activerecord/lib/active_record/attribute.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb index cacde0f6fd..9530f134d0 100644 --- a/activerecord/lib/active_record/attribute.rb +++ b/activerecord/lib/active_record/attribute.rb @@ -205,6 +205,8 @@ module ActiveRecord end class Uninitialized < Attribute # :nodoc: + UNINITIALIZED_ORIGINAL_VALUE = Object.new + def initialize(name, type) super(name, nil, type) end @@ -215,6 +217,10 @@ module ActiveRecord end end + def original_value + UNINITIALIZED_ORIGINAL_VALUE + end + def value_for_database end -- cgit v1.2.3