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