naive implementation of post_count on categories

This commit is contained in:
Sam
2013-10-17 13:23:38 +11:00
parent 9ad01a1afb
commit 7bf96ee690
4 changed files with 39 additions and 6 deletions

View File

@@ -0,0 +1,14 @@
class AddPostCountToCategories < ActiveRecord::Migration
def up
add_column :categories, :post_count, :integer, null: false, default: 0
execute <<SQL
UPDATE categories
SET post_count = (SELECT SUM(posts_count) FROM topics
WHERE category_id = categories.id AND deleted_at IS NULL)
SQL
end
def down
remove_column :categories, :post_count
end
end