FIX: Inherit topic auto close when changing topic's category.

This commit is contained in:
Guo Xiang Tan
2017-05-31 17:40:21 +09:00
parent 2302493c64
commit b0dd05fdc6
2 changed files with 69 additions and 49 deletions

View File

@@ -170,7 +170,6 @@ class Topic < ActiveRecord::Base
before_create do
initialize_default_values
inherit_auto_close_from_category
end
after_create do
@@ -187,6 +186,10 @@ class Topic < ActiveRecord::Base
if title_changed?
write_attribute :fancy_title, Topic.fancy_title(title)
end
if category_id_changed? || new_record?
inherit_auto_close_from_category
end
end
after_save do
@@ -614,8 +617,7 @@ SQL
old_category = category
if self.category_id != new_category.id
self.category_id = new_category.id
self.update_column(:category_id, new_category.id)
self.update!(category_id: new_category.id)
Category.where(id: old_category.id).update_all("topic_count = topic_count - 1") if old_category
# when a topic changes category we may have to start watching it