2024-07-10 13:29:18 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StorageLocation < ApplicationRecord
|
|
|
|
include Discard::Model
|
|
|
|
ID_PREFIX = 'SL'
|
|
|
|
include PrefixedIdModel
|
|
|
|
|
|
|
|
default_scope -> { kept }
|
|
|
|
|
|
|
|
has_one_attached :image
|
|
|
|
|
|
|
|
belongs_to :team
|
|
|
|
belongs_to :parent, class_name: 'StorageLocation', optional: true
|
|
|
|
belongs_to :created_by, class_name: 'User'
|
|
|
|
|
|
|
|
has_many :storage_location_repository_rows, inverse_of: :storage_location
|
|
|
|
has_many :repository_rows, through: :storage_location_repository_row
|
|
|
|
|
|
|
|
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
|
|
|
|
|
|
|
after_discard do
|
2024-07-11 13:54:44 +08:00
|
|
|
StorageLocation.where(parent_id: id).find_each(&:discard)
|
2024-07-10 13:29:18 +08:00
|
|
|
storage_location_repository_rows.each(&:discard)
|
|
|
|
end
|
|
|
|
end
|