提交 c587b636 编写于 作者: S Sean Griffin

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
上级 b604dd0b
......@@ -205,6 +205,8 @@ def with_value_from_database(value)
end
class Uninitialized < Attribute # :nodoc:
UNINITIALIZED_ORIGINAL_VALUE = Object.new
def initialize(name, type)
super(name, nil, type)
end
......@@ -215,6 +217,10 @@ def value
end
end
def original_value
UNINITIALIZED_ORIGINAL_VALUE
end
def value_for_database
end
......
......@@ -734,6 +734,17 @@ def catchphrase
assert_equal "arr", pirate.catchphrase
end
test "attributes assigned but not selected are dirty" do
person = Person.select(:id).first
refute person.changed?
person.first_name = "Sean"
assert person.changed?
person.first_name = nil
assert person.changed?
end
private
def with_partial_writes(klass, on = true)
old = klass.partial_writes?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册