|
- # == 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
-
- def to_builder
- Jbuilder.new do |priority|
- priority.(self, :id, :name)
- end
- end
- end
|