2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2014-08-23 22:29:04 +00:00
|
|
|
|
|
|
|
class ObjectLookup < ApplicationModel
|
|
|
|
|
2016-01-24 00:14:14 +00:00
|
|
|
def self.by_id(id)
|
2014-08-23 22:29:04 +00:00
|
|
|
# lookup
|
2016-01-24 00:14:14 +00:00
|
|
|
lookup = self.lookup(id: id)
|
2014-08-24 08:04:20 +00:00
|
|
|
return if !lookup
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2014-08-24 08:04:20 +00:00
|
|
|
lookup.name
|
2014-08-23 22:29:04 +00:00
|
|
|
end
|
|
|
|
|
2016-01-24 00:14:14 +00:00
|
|
|
def self.by_name(name)
|
2014-08-23 22:29:04 +00:00
|
|
|
# lookup
|
2016-01-24 00:14:14 +00:00
|
|
|
lookup = self.lookup(name: name)
|
2014-08-24 08:04:20 +00:00
|
|
|
if lookup
|
|
|
|
return lookup.id
|
2014-08-23 22:29:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# create
|
2016-01-24 00:14:14 +00:00
|
|
|
lookup = create(name: name)
|
2014-08-24 08:04:20 +00:00
|
|
|
lookup.id
|
2014-08-23 22:29:04 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|