From f7fa452d88db8174dacfff08442161c5a7534ed2 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 5 Apr 2013 13:09:45 -0400 Subject: [PATCH] fixes #1200 --- app/models/comment.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 74701a14b..213907387 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -102,8 +102,11 @@ class Comment < ActiveRecord::Base end def update_last_commented_at_on_destroy - if Comment.where("post_id = ? and id <> ?", post_id, id).count == 0 + other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order("id DESC") + if other_comments.count == 0 Post.update_all("last_commented_at = NULL", ["id = ?", post_id]) + else + Post.update_all(["last_commented_at = ?", other_comments.first.created_at], ["id = ?", post_id]) end true end