From 9ac6a5042bd97dcc17b66348d603df2b9782777d Mon Sep 17 00:00:00 2001 From: Anton Katunin Date: Thu, 25 Jul 2024 17:11:26 +1000 Subject: [PATCH] any_changed? is true for new records --- lib/active_interaction/extras/model_fields.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_interaction/extras/model_fields.rb b/lib/active_interaction/extras/model_fields.rb index cc7438b..1948b7f 100644 --- a/lib/active_interaction/extras/model_fields.rb +++ b/lib/active_interaction/extras/model_fields.rb @@ -81,14 +81,18 @@ def given_model_fields(model_name) # the one on the model def any_changed?(*fields) fields.any? do |field| - if inputs.given?(field) - model_field = self.class.model_field_cache_inverse[field] - - if model_field - send(model_field).send(field) != send(field) - else + model_field = self.class.model_field_cache_inverse[field] + if model_field + model = send(model_field) + if model.new_record? true + elsif inputs.given?(field) + model.send(field) != send(field) + else + false end + else + inputs.given?(field) end end end