Skip to content

Commit

Permalink
any_changed? is true for new records
Browse files Browse the repository at this point in the history
  • Loading branch information
antulik committed Jul 25, 2024
1 parent d33114d commit 9ac6a50
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/active_interaction/extras/model_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ac6a50

Please sign in to comment.