Created
April 1, 2013 15:08
-
-
Save valachi/5285456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddCommentsCountToArticles < ActiveRecord::Migration | |
def up | |
add_column :articles, :comments_count, :integer, null: false, default: 0 | |
Article.reset_column_information | |
ids = Set.new | |
Article.all.each {|art| ids << art.id} | |
ids.each do |article_id| | |
Article.reset_counters(article_id, :comments) | |
end | |
end | |
def down | |
remove_column :articles, :comments_count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment