Commit 36c199ae1c9b086c102af46276adbe03ece7d079
1 parent
d0472735
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Add counter cache for article followers
Showing
2 changed files
with
16 additions
and
1 deletions
Show diff stats
app/models/article_follower.rb
db/migrate/20150909091347_add_followers_count_to_article.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +class AddFollowersCountToArticle < ActiveRecord::Migration | |
2 | + | |
3 | + def self.up | |
4 | + add_column :articles, :followers_count, :integer, :default => 0 | |
5 | + add_column :article_versions, :followers_count, :integer | |
6 | + | |
7 | + execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)" | |
8 | + end | |
9 | + | |
10 | + def self.down | |
11 | + remove_column :article_versions, :followers_count | |
12 | + remove_column :articles, :followers_count | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |