posts: don't reparent children when expunging posts.

If an expunged post has children, just set their parent to null instead
of reparenting them. Before we reparented them to the oldest child.
This commit is contained in:
evazion
2020-08-04 12:28:20 -05:00
parent b57122cf7f
commit f9aa1e9718
2 changed files with 1 additions and 24 deletions

View File

@@ -920,14 +920,7 @@ class Post < ApplicationRecord
end
def update_children_on_destroy
return unless children.present?
eldest = children[0]
siblings = children[1..-1]
eldest.update(parent_id: nil)
Post.where(id: siblings).find_each { |p| p.update(parent_id: eldest.id) }
# Post.where(id: siblings).update(parent_id: eldest.id) # XXX rails 5
children.update(parent: nil)
end
def update_parent_on_save