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