has_links.rb 438 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module HasLinks
  3. extend ActiveSupport::Concern
  4. included do
  5. before_destroy :links_destroy
  6. end
  7. =begin
  8. delete object link list, will be executed automatically
  9. model = Model.find(123)
  10. model.links_destroy
  11. =end
  12. def links_destroy
  13. Link.remove_all(
  14. link_object: self.class.to_s,
  15. link_object_value: id,
  16. )
  17. true
  18. end
  19. end