2019-05-07 19:47:50 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-07 22:28:28 +08:00
|
|
|
class RepositoryListItem < ApplicationRecord
|
2020-01-15 18:28:31 +08:00
|
|
|
has_many :repository_list_values, inverse_of: :repository_list_item, dependent: :destroy
|
2018-02-12 16:05:41 +08:00
|
|
|
belongs_to :repository_column, inverse_of: :repository_list_items
|
2019-05-07 19:47:50 +08:00
|
|
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
|
|
|
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
2020-02-03 22:20:01 +08:00
|
|
|
validate :validate_per_column_limit
|
2018-02-09 23:28:21 +08:00
|
|
|
validates :data,
|
2018-02-07 22:28:28 +08:00
|
|
|
presence: true,
|
2019-05-07 19:47:50 +08:00
|
|
|
uniqueness: { scope: :repository_column_id, case_sensitive: false },
|
2018-02-07 22:28:28 +08:00
|
|
|
length: { maximum: Constants::TEXT_MAX_LENGTH }
|
2020-02-03 22:20:01 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_per_column_limit
|
2020-02-03 22:48:49 +08:00
|
|
|
if repository_column &&
|
|
|
|
repository_column.repository_list_items.count > Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN
|
2020-02-03 22:20:01 +08:00
|
|
|
errors.add(:base, :per_column_limit)
|
|
|
|
end
|
|
|
|
end
|
2018-02-07 22:28:28 +08:00
|
|
|
end
|