1
0
Fork 0
dokkan-data-rails/db/migrate/20151103193404_add_links_counter_cache_to_cards.rb

14 lines
339 B
Ruby

class AddLinksCounterCacheToCards < ActiveRecord::Migration
def up
add_column :cards, :links_count, :integer, default: 0, null: false
Card.reset_column_information
Card.find_each do |card|
card.update_attribute(:links_count, card.links.count)
end
end
def down
remove_column :cards, :links_count
end
end