Fix topic merge
It was merging in the wrong direction, and didn't update response count.
This commit is contained in:
@@ -78,7 +78,7 @@ class ForumTopicsController < ApplicationController
|
|||||||
@forum_topic = ForumTopic.find(params[:id])
|
@forum_topic = ForumTopic.find(params[:id])
|
||||||
@merged_topic = ForumTopic.find(params[:merged_id])
|
@merged_topic = ForumTopic.find(params[:merged_id])
|
||||||
@forum_topic.merge(@merged_topic)
|
@forum_topic.merge(@merged_topic)
|
||||||
redirect_to forum_topic_path(@forum_topic)
|
redirect_to forum_topic_path(@merged_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -151,7 +151,8 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def merge(topic)
|
def merge(topic)
|
||||||
ForumPost.where(:id => topic.posts.map(&:id)).update_all(:topic_id => id)
|
ForumPost.where(:id => self.posts.map(&:id)).update_all(:topic_id => topic.id)
|
||||||
update_attribute(:is_deleted, true)
|
topic.update_attribute(:response_count, topic.response_count + self.posts.length)
|
||||||
|
self.update_columns(:response_count => 0, :is_deleted => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user