Remove topic links when a post is deleted

This commit is contained in:
Neil Lalonde
2013-06-13 13:41:45 -04:00
parent 49c09898e2
commit 4db8204a15
5 changed files with 57 additions and 13 deletions

View File

@@ -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

View File

@@ -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