From 8cd38399f957031153c46f18a5dcb156c1c64e6f Mon Sep 17 00:00:00 2001 From: Sofia Sousa Date: Mon, 14 Mar 2022 12:20:35 +0000 Subject: [PATCH] Update dynamic_attributes.rb --- lib/dynamic_attributes.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/dynamic_attributes.rb b/lib/dynamic_attributes.rb index 5d33132..74fd420 100644 --- a/lib/dynamic_attributes.rb +++ b/lib/dynamic_attributes.rb @@ -73,6 +73,13 @@ def update_attributes(attributes) set_dynamic_attributes(attributes) super(attributes) end + + # Overrides update to take dynamic attributes into account + # (Rails 6.1 ActiveRecord deprecates update_attributes methods) + def update(attributes) + set_dynamic_attributes(attributes) + super(attributes) + end # Creates an accessor when a non-existing setter with the configured dynamic attribute prefix is detected. Calls super otherwise. def method_missing(method, *arguments, &block) @@ -120,7 +127,7 @@ def set_dynamic_attribute(att, value = nil) update_dynamic_attribute(att, value) end - # Called on object initialization or when calling update_attributes to convert passed dynamic attributes + # Called on object initialization or when calling update_attributes/update to convert passed dynamic attributes # into attributes that will be persisted by calling set_dynamic_attribute if it does not exist already. # The serialization column will also be updated and the detected dynamic attributes are removed from the passed # attributes hash.