Merge pull request #1556 from eriko/patch-1
Update 20131017014509_add_post_count_to_categories.rb
This commit is contained in:
commit
4bf064c3c6
|
@ -3,7 +3,7 @@ class AddPostCountToCategories < ActiveRecord::Migration
|
||||||
add_column :categories, :post_count, :integer, null: false, default: 0
|
add_column :categories, :post_count, :integer, null: false, default: 0
|
||||||
execute <<SQL
|
execute <<SQL
|
||||||
UPDATE categories
|
UPDATE categories
|
||||||
SET post_count = (SELECT SUM(posts_count) FROM topics
|
SET post_count = (SELECT COALESCE(SUM(posts_count),0) FROM topics
|
||||||
WHERE category_id = categories.id AND deleted_at IS NULL)
|
WHERE category_id = categories.id AND deleted_at IS NULL)
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue