creddit/db/migrate/20150804000313_add_comments_count_to_post.rb

11 lines
267 B
Ruby
Raw Normal View History

2015-07-16 11:57:27 -04:00
class AddCommentsCountToPost < ActiveRecord::Migration
def change
add_column :posts, :comments_count, :integer, default: 0
Post.reset_column_information
Post.all.each do |p|
p.update_attribute :comments_count, p.comments.length
end
end
end