gitlab-org--gitlab-foss/app/models/concerns/internal_id.rb

24 lines
512 B
Ruby
Raw Normal View History

module InternalId
extend ActiveSupport::Concern
included do
validate :set_iid, on: :create
validates :iid, presence: true, numericality: true
end
def set_iid
if iid.blank?
2017-07-07 11:08:49 -04:00
parent = project || group
records = parent.public_send(self.class.name.tableize) # rubocop:disable GitlabSecurity/PublicSend
records = records.with_deleted if self.paranoid?
max_iid = records.maximum(:iid)
2016-03-14 16:46:44 -04:00
self.iid = max_iid.to_i + 1
end
end
def to_param
iid.to_s
end
end