mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Remove topic links when a post is deleted
This commit is contained in:
@@ -25,6 +25,7 @@ class Post < ActiveRecord::Base
|
||||
has_many :post_replies
|
||||
has_many :replies, through: :post_replies
|
||||
has_many :post_actions
|
||||
has_many :topic_links
|
||||
|
||||
has_and_belongs_to_many :upload
|
||||
|
||||
@@ -52,9 +53,15 @@ class Post < ActiveRecord::Base
|
||||
@types ||= Enum.new(:regular, :moderator_action)
|
||||
end
|
||||
|
||||
def trash!
|
||||
self.topic_links.each(&:destroy)
|
||||
super
|
||||
end
|
||||
|
||||
def recover!
|
||||
super
|
||||
update_flagged_posts_count
|
||||
TopicLink.extract_from(self)
|
||||
end
|
||||
|
||||
# The key we use in redis to ensure unique posts
|
||||
|
||||
@@ -13,7 +13,7 @@ class TopicLink < ActiveRecord::Base
|
||||
|
||||
validates_uniqueness_of :url, scope: [:topic_id, :post_id]
|
||||
|
||||
has_many :topic_link_clicks
|
||||
has_many :topic_link_clicks, dependent: :destroy
|
||||
|
||||
validate :link_to_self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user