Guest User

Untitled

a guest
May 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. class AddCounterCacheToTags < ActiveRecord::Migration
  2. def self.up
  3. add_column :tags, :taggings_count, :integer, :default=>0
  4. Tag.reset_column_information
  5. Tag.find(:all).each do |tag|
  6. tag.update_attribute :taggings_count, tag.taggings.length
  7. end
  8. end
  9.  
  10. def self.down
  11. remove_column :tags, :taggings_count
  12. end
  13. end
Add Comment
Please, Sign In to add comment