2020-01-14 23:55:10 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RepositoryChecklistItemsValue < ApplicationRecord
|
|
|
|
belongs_to :repository_checklist_item
|
2024-02-05 20:36:12 +08:00
|
|
|
belongs_to :repository_checklist_value, inverse_of: :repository_checklist_items_values
|
2020-01-14 23:55:10 +08:00
|
|
|
|
|
|
|
validates :repository_checklist_item, :repository_checklist_value, presence: true
|
2024-05-29 23:18:00 +08:00
|
|
|
|
2024-07-17 16:22:44 +08:00
|
|
|
after_commit :touch_repository_checklist_value
|
2024-05-29 23:18:00 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
|
|
|
def touch_repository_checklist_value
|
2024-07-17 16:22:44 +08:00
|
|
|
# check if value was deleted, if so, touch repositroy_row directly
|
|
|
|
if RepositoryChecklistValue.exists?(repository_checklist_value.id)
|
|
|
|
repository_checklist_value.touch
|
|
|
|
elsif RepositoryRow.exists?(repository_checklist_value.repository_cell.repository_row.id)
|
|
|
|
repository_checklist_value.repository_cell.repository_row.touch
|
|
|
|
end
|
2024-05-29 23:18:00 +08:00
|
|
|
end
|
|
|
|
# rubocop:enable Rails/SkipsModelValidations
|
2020-01-14 23:55:10 +08:00
|
|
|
end
|