object_lookup.rb 420 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ObjectLookup < ApplicationModel
  3. def self.by_id(id)
  4. # lookup
  5. lookup = self.lookup(id: id)
  6. return if !lookup
  7. lookup.name
  8. end
  9. def self.by_name(name)
  10. # lookup
  11. lookup = self.lookup(name: name)
  12. if lookup
  13. return lookup.id
  14. end
  15. # create
  16. lookup = create(name: name)
  17. lookup.id
  18. end
  19. end