can_latest_change.rb 568 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationModel::CanLatestChange
  3. extend ActiveSupport::Concern
  4. # methods defined here are going to extend the class, not the instance of it
  5. class_methods do
  6. =begin
  7. get latest updated_at object timestamp
  8. latest_change = object.latest_change
  9. returns
  10. result = timestamp
  11. =end
  12. def latest_change
  13. data = order('updated_at DESC, id DESC').limit(1).pick(:id, :updated_at)
  14. return if data.blank?
  15. "#{data[0]},#{data[1]&.to_s(:nsec)}"
  16. end
  17. end
  18. end