From d2f2a142b9485f21978040bfd5a6d7745588ee9a Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 19 Apr 2013 15:35:36 -0700 Subject: [PATCH] fixes #1361 --- app/models/post.rb | 4 ++-- script/fixes/013.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 3154f1026..fbf65e98f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -26,9 +26,9 @@ class Post < ActiveRecord::Base has_many :versions, :class_name => "PostVersion", :dependent => :destroy, :order => "post_versions.id ASC" has_many :votes, :class_name => "PostVote", :dependent => :destroy has_many :notes, :dependent => :destroy - has_many :comments, :order => "comments.id" + has_many :comments, :order => "comments.id", :dependent => :destroy has_many :children, :class_name => "Post", :foreign_key => "parent_id", :order => "posts.id" - has_many :disapprovals, :class_name => "PostDisapproval" + has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy validates_uniqueness_of :md5 validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?} attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :builder, :privileged, :platinum, :contributor, :janitor, :moderator, :admin, :default] diff --git a/script/fixes/013.rb b/script/fixes/013.rb index 3d336f464..e6bb4c36d 100644 --- a/script/fixes/013.rb +++ b/script/fixes/013.rb @@ -5,5 +5,11 @@ 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) + post.update_column(:score, post.up_score + post.down_score + post.fav_count) +end + +Comment.find_each do |comment| + if !Post.exists?("id = #{comment.post_id}") + comment.destroy + end end