Skip to content

Instantly share code, notes, and snippets.

@mockra
Created April 9, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mockra/10308296 to your computer and use it in GitHub Desktop.
Save mockra/10308296 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post, counter_cache: true
end
# Migration
add_column :posts, :comments_count, :integer, default: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment