Skip to content

Commit bc34f35

Browse files
authored
Merge pull request rails#48177 from eileencodes/unrevert-46444
Revert "Merge pull request rails#46444 from eileencodes/revert-forgetting-…
2 parents 05a45c1 + 3814168 commit bc34f35

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

activemodel/lib/active_model/attribute.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ def type_cast(value)
175175
type.deserialize(value)
176176
end
177177

178+
def forgetting_assignment
179+
# If this attribute was not persisted (with a `value_for_database`
180+
# that might differ from `value_before_type_cast`) and `value` has not
181+
# changed in place, we can simply dup this attribute to avoid
182+
# deserialize / cast / serialize calls from computing the new
183+
# attribute's `value_before_type_cast`.
184+
if !defined?(@value_for_database) && !changed_in_place?
185+
dup
186+
else
187+
super
188+
end
189+
end
190+
178191
private
179192
def _original_value_for_database
180193
value_before_type_cast

0 commit comments

Comments
 (0)