Files
docuseal/app/models/template_folder.rb
T

55 lines
1.6 KiB
Ruby
Raw Normal View History

2023-09-21 00:23:38 +03:00
# frozen_string_literal: true
# == Schema Information
#
# Table name: template_folders
#
2025-07-20 08:28:19 +03:00
# id :bigint not null, primary key
# archived_at :datetime
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# author_id :bigint not null
# parent_folder_id :bigint
2023-09-21 00:23:38 +03:00
#
# Indexes
#
2025-07-20 08:28:19 +03:00
# index_template_folders_on_account_id (account_id)
# index_template_folders_on_author_id (author_id)
# index_template_folders_on_parent_folder_id (parent_folder_id)
2023-09-21 00:23:38 +03:00
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (author_id => users.id)
2025-07-20 08:28:19 +03:00
# fk_rails_... (parent_folder_id => template_folders.id)
2023-09-21 00:23:38 +03:00
#
class TemplateFolder < ApplicationRecord
DEFAULT_NAME = 'Default'
belongs_to :author, class_name: 'User'
belongs_to :account
2025-07-20 08:28:19 +03:00
belongs_to :parent_folder, class_name: 'TemplateFolder', optional: true
2023-09-21 00:23:38 +03:00
2023-09-22 02:20:38 +03:00
has_many :templates, dependent: :destroy, foreign_key: :folder_id, inverse_of: :folder
2025-07-20 08:28:19 +03:00
has_many :subfolders, class_name: 'TemplateFolder', foreign_key: :parent_folder_id, inverse_of: :parent_folder,
dependent: :destroy
2023-12-30 00:37:03 +02:00
has_many :active_templates, -> { where(archived_at: nil) },
2023-09-22 02:20:38 +03:00
class_name: 'Template', dependent: :destroy, foreign_key: :folder_id, inverse_of: :folder
2023-09-21 00:23:38 +03:00
2023-12-30 00:37:03 +02:00
scope :active, -> { where(archived_at: nil) }
2023-09-22 02:20:38 +03:00
2025-07-20 08:28:19 +03:00
def full_name
if parent_folder_id?
[parent_folder.name, name].join(' / ')
else
name
end
end
2023-09-22 02:20:38 +03:00
def default?
name == DEFAULT_NAME
end
2023-09-21 00:23:38 +03:00
end