Created
June 23, 2010 13:13
-
-
Save adamico/449901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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