gitlab-org--gitlab-foss/app/models/concerns/internal_id.rb
Zeger-Jan van de Weg 212e83bab3 Soft delete issuables
2016-03-19 21:23:03 +01:00

22 lines
510 B
Ruby

module InternalId
extend ActiveSupport::Concern
included do
validate :set_iid, on: :create
validates :iid, presence: true, numericality: true
end
def set_iid
max_iid = case self.class
when Issue, MergeRequest
project.send(self.class.name.tableize).with_deleted.maximum(:iid)
else
project.send(self.class.name.tableize).maximum(:iid)
end
self.iid = max_iid.to_i + 1
end
def to_param
iid.to_s
end
end