From 026ca4482963d762ce6b24b40381fe71be58e6e8 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Sun, 21 Apr 2013 11:45:46 -0700 Subject: [PATCH] fix script updates --- script/fixes/013.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/script/fixes/013.rb b/script/fixes/013.rb index 5968ec9ee..a4b40ed26 100644 --- a/script/fixes/013.rb +++ b/script/fixes/013.rb @@ -4,12 +4,16 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', ActiveRecord::Base.connection.execute("set statement_timeout = 0") -Post.select("id, score, up_score, down_score, fav_count").find_each do |post| - post.update_column(:score, post.up_score + post.down_score + post.fav_count) -end ; true - Comment.find_each do |comment| if !Post.exists?("id = #{comment.post_id}") comment.destroy end -end ; true \ No newline at end of file +end ; true + +Post.find_each do |post| + post.update_column(:fav_count, Favorite.where("post_id = #{post.id}").count) +end + +Post.select("id, score, up_score, down_score, fav_count").find_each do |post| + post.update_column(:score, post.up_score + post.down_score) +end ; true