mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
properly orphan deleted docs when also deleting folders
This commit is contained in:
parent
2ab4c34fd7
commit
70fe58b90a
@ -17,7 +17,8 @@ class FoldersController < ApplicationController
|
||||
|
||||
def destroy
|
||||
# Relocate all documents in this folder to the root "folder"
|
||||
Document.where(folder_id: @folder.id).update_all(folder_id: nil)
|
||||
# TODO - I think we can handle this at the model association level with dependent: nullify, but I've never used it
|
||||
Document.with_deleted.where(folder_id: @folder.id).update_all(folder_id: nil)
|
||||
|
||||
# Relocate all child folders in this folder to the root "folder"
|
||||
Folder.where(parent_folder_id: @folder.id).update_all(parent_folder_id: nil)
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
class Folder < ApplicationRecord
|
||||
has_many :documents
|
||||
|
||||
belongs_to :parent_folder, optional: true, class_name: Folder.name, foreign_key: :parent_folder_id
|
||||
belongs_to :user
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user