Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use counter_cache with acts_as_commentable and rails 4.2 #103

Open
eduardm opened this issue Apr 13, 2016 · 1 comment
Open

How to use counter_cache with acts_as_commentable and rails 4.2 #103

eduardm opened this issue Apr 13, 2016 · 1 comment

Comments

@eduardm
Copy link

eduardm commented Apr 13, 2016

I think it will be useful to be able to use counter_cache with acts_as_commentable, could save a lot of processing time on large sites

@bufordtaylor
Copy link

Should work smoothly like normal

add_column :projects, :comments_count, :integer, :default => 0
Project.all.find_each do |p|
   Project.update_counters p.id, :comments_count => p.root_comments.length
end

then in comment.rb

  belongs_to :commentable, :polymorphic => true, :counter_cache => :comments_count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants