Method: Core::Models::Concerns::Historizable#add_history
- Defined in:
- lib/core/models/concerns/historizable.rb
#add_history(field:, from:, to:) ⇒ Object
Adds an entry in the history table for the given field. It checks several things to make the history entry valid :
-
the new value is different from the old value
-
the old value is identical to the last recorded new value.
28 29 30 31 32 33 34 |
# File 'lib/core/models/concerns/historizable.rb', line 28 def add_history(field:, from:, to:) return if from == to return if !history.empty? && history.order_by(:created_at.desc).first.to != from event = Core::Models::Event.create(field: field, from: from, to: to, document: self) event.save end |