BigW Consortium Gitlab

internal_id.rb 430 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
module InternalId
  extend ActiveSupport::Concern

  included do
    validate :set_iid, on: :create
    validates :iid, presence: true, numericality: true
  end

  def set_iid
10 11 12 13
    if iid.blank?
      records = project.send(self.class.name.tableize)
      records = records.with_deleted if self.paranoid?
      max_iid = records.maximum(:iid)
14

15 16
      self.iid = max_iid.to_i + 1
    end
17 18 19 20 21 22
  end

  def to_param
    iid.to_s
  end
end