mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
Update 20131017014509_add_post_count_to_categories.rb
In case the category does not have any posts yet. You get a null value error running the migration if this is the case.
This commit is contained in:
parent
d10f9f756f
commit
fe0dc8161a
@ -3,7 +3,7 @@ class AddPostCountToCategories < ActiveRecord::Migration
|
||||
add_column :categories, :post_count, :integer, null: false, default: 0
|
||||
execute <<SQL
|
||||
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)
|
||||
SQL
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user