summaryrefslogtreecommitdiff
path: root/app/models/concerns/internal_id.rb
blob: 821ed54fb987568a3fd41c638709127e1fefccb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module InternalId
  extend ActiveSupport::Concern

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

  def set_iid
    max_iid = project.send(self.class.name.tableize).maximum(:iid)
    self.iid = max_iid.to_i + 1
  end

  def to_param
    iid.to_s
  end
end