move model code out of migration

This commit is contained in:
David Gil
2015-08-12 13:46:02 +02:00
parent 1ee3378768
commit 7c8948639f
2 changed files with 2 additions and 5 deletions

View File

@@ -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

View File

@@ -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