]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20121005195010_add_diary_entry_counter_caches.rb
use a controller method to handle cancan denials
[rails.git] / db / migrate / 20121005195010_add_diary_entry_counter_caches.rb
1 class AddDiaryEntryCounterCaches < ActiveRecord::Migration[5.0]
2   def self.up
3     add_column :users, :diary_entries_count, :integer, :null => false, :default => 0
4
5     DiaryEntry.group(:user_id).pluck(:user_id).each do |user_id|
6       User.reset_counters(user_id, :diary_entries)
7     end
8   end
9
10   def self.down
11     remove_column :users, :diary_entries_count
12   end
13 end