gitlab-org--gitlab-foss/app/models/label.rb

27 lines
666 B
Ruby
Raw Normal View History

class Label < ActiveRecord::Base
belongs_to :project
has_many :label_links, dependent: :destroy
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
2014-08-11 21:59:30 +00:00
validates :color,
format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ },
allow_blank: false
validates :project, presence: true
2014-08-11 21:59:30 +00:00
# Don't allow '?', '&', and ',' for label titles
2014-08-12 08:53:50 +00:00
validates :title,
presence: true,
format: { with: /\A[^&\?,&]*\z/ },
2014-08-13 12:12:05 +00:00
uniqueness: { scope: :project_id }
scope :order_by_name, -> { reorder("labels.title ASC") }
def name
title
end
def open_issues_count
issues.opened.count
end
end