Skip to content

Instantly share code, notes, and snippets.

@mikekellyio
Last active December 28, 2015 22:19
Show Gist options
  • Save mikekellyio/7570771 to your computer and use it in GitHub Desktop.
Save mikekellyio/7570771 to your computer and use it in GitHub Desktop.
def AddCounterCache < ActiveRecord::Migration
def change
add_column :users, :posts_count, :integer
#Prime the pump!!!
User.find_each do |u|
u.update_attribute(:posts_count, u.posts.count)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment