mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: delete post action from permanently deleted posts (#12309)
When Post is permanently deleted, we should delete correlated PostAction as well.
This commit is contained in:
parent
7e470bf8ae
commit
c5a116859d
@ -34,7 +34,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :post_replies
|
has_many :post_replies
|
||||||
has_many :replies, through: :post_replies
|
has_many :replies, through: :post_replies
|
||||||
has_many :post_actions
|
has_many :post_actions, dependent: :destroy
|
||||||
has_many :topic_links
|
has_many :topic_links
|
||||||
has_many :group_mentions, dependent: :destroy
|
has_many :group_mentions, dependent: :destroy
|
||||||
|
|
||||||
|
19
db/migrate/20210308010745_delete_orphan_post_actions.rb
Normal file
19
db/migrate/20210308010745_delete_orphan_post_actions.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class DeleteOrphanPostActions < ActiveRecord::Migration[6.0]
|
||||||
|
def up
|
||||||
|
sql = <<~SQL
|
||||||
|
DELETE FROM post_actions
|
||||||
|
USING post_actions pa
|
||||||
|
LEFT JOIN posts ON posts.id = pa.post_id
|
||||||
|
WHERE posts.id IS NULL
|
||||||
|
AND post_actions.id = pa.id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute(sql)
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user