mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-16 06:06:56 +08:00
25 lines
693 B
Ruby
25 lines
693 B
Ruby
# 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
|
|
StorageLocation.where(parent_id: id).find_each(&:discard)
|
|
storage_location_repository_rows.each(&:discard)
|
|
end
|
|
end
|