From 7c8948639fce8e671297eb53300707f7ae449dc1 Mon Sep 17 00:00:00 2001 From: David Gil Date: Wed, 12 Aug 2015 13:46:02 +0200 Subject: [PATCH] move model code out of migration --- app/models/comment.rb | 3 ++- db/migrate/20150811161459_add_children_count_to_comments.rb | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index f298c67c3..696b363ce 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -34,7 +34,8 @@ class Comment < ActiveRecord::Base # TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache # Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed - # There is a test for this, so you should know if it is actually fixed. + # and reset counters using + # > Comment.find_each { |comment| Comment.reset_counters(comment.id, :children) } def children_count children.count end diff --git a/db/migrate/20150811161459_add_children_count_to_comments.rb b/db/migrate/20150811161459_add_children_count_to_comments.rb index 74c288ff5..ce233542d 100644 --- a/db/migrate/20150811161459_add_children_count_to_comments.rb +++ b/db/migrate/20150811161459_add_children_count_to_comments.rb @@ -1,10 +1,6 @@ class AddChildrenCountToComments < ActiveRecord::Migration def up add_column :comments, :children_count, :integer, default: 0 - - Comment.find_each do |comment| - Comment.reset_counters(comment.id, :children) - end end def down