gitlink-forgeplus/app/models/issue_priority.rb

36 lines
797 B
Ruby

# == Schema Information
#
# Table name: issue_priorities
#
# id :integer not null, primary key
# name :string(255)
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_issue_priorities_on_name (name)
#
class IssuePriority < ApplicationRecord
has_many :issues
def self.init_data
map = {
"1" => "",
"2" => "正常",
"3" => "",
"4" => "紧急"
}
IssuePriority.order(id: :asc).each do |prty|
if map["#{prty.id}"] == prty.name
IssuePriority.find_or_create_by(id: prty.id, name: prty.name)
else
Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)}
prty.destroy!
end
end
end
end