object_lookup.rb 419 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://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