scinote-web/app/models/repository_checklist_item.rb

26 lines
1 KiB
Ruby
Raw Normal View History

2019-12-06 20:18:35 +08:00
# frozen_string_literal: true
2019-12-09 20:38:40 +08:00
class RepositoryChecklistItem < ApplicationRecord
2019-12-06 20:18:35 +08:00
belongs_to :repository_column
2019-12-06 21:16:20 +08:00
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User',
2019-12-09 20:38:40 +08:00
inverse_of: :created_repository_checklist_types
2019-12-06 21:16:20 +08:00
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User',
2019-12-09 20:38:40 +08:00
inverse_of: :modified_repository_checklist_types
has_many :repository_checklist_items_values, dependent: :destroy
has_many :repository_checklist_values, through: :repository_checklist_items_values, dependent: :destroy
validate :validate_per_column_limit
validates :data, presence: true,
uniqueness: { scope: :repository_column_id, case_sensitive: false },
length: { maximum: Constants::NAME_MAX_LENGTH }
private
def validate_per_column_limit
2020-02-03 22:48:49 +08:00
if repository_column &&
repository_column.repository_checklist_items.count > Constants::REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN
errors.add(:base, :per_column_limit)
end
end
2019-12-06 20:18:35 +08:00
end