1 class AddDiaryEntryCounterCaches < ActiveRecord::Migration[4.2]
3 add_column :users, :diary_entries_count, :integer, :null => false, :default => 0
5 DiaryEntry.group(:user_id).pluck(:user_id).each do |user_id|
6 User.reset_counters(user_id, :diary_entries)
11 remove_column :users, :diary_entries_count