Skip to content

Instantly share code, notes, and snippets.

@adamico
Created June 23, 2010 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamico/449901 to your computer and use it in GitHub Desktop.
Save adamico/449901 to your computer and use it in GitHub Desktop.
class AddAppelsCount < ActiveRecord::Migration
def self.up
models = %w(expo_types contextes)
models.each do |model|
add_column model, :appels_count, :integer, :default => 0
klass = model.classify.constantize
klass.reset_column_information
klass.all.each do |instance|
klass.update_counters instance.id, :appels_count => instance.appels.length
end
end
end
def self.down
remove_column :contextes, :appels_count
remove_column :expo_types, :appels_count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment