add folders migration

This commit is contained in:
Alex Turchyn
2023-09-21 00:23:38 +03:00
parent 9bcf5aacc0
commit ef8c3cfe7f
8 changed files with 129 additions and 2 deletions
+9
View File
@@ -16,6 +16,9 @@ class Account < ApplicationRecord
has_many :encrypted_configs, dependent: :destroy
has_many :account_configs, dependent: :destroy
has_many :templates, dependent: :destroy
has_many :template_folders, dependent: :destroy
has_one :default_folder, -> { where(name: TemplateFolder::DEFAULT_NAME) },
class_name: 'TemplateFolder', dependent: :destroy, inverse_of: :account
has_many :submissions, through: :templates
has_many :submitters, through: :submissions
has_many :active_users, -> { active }, dependent: :destroy,
@@ -23,4 +26,10 @@ class Account < ApplicationRecord
attribute :timezone, :string, default: 'UTC'
attribute :locale, :string, default: 'en-US'
def default_folder
super || template_folders.new(name: TemplateFolder::DEFAULT_NAME,
author_id: users.minimum(:id))
.tap(&:save!)
end
end