Browse Source

Make migration robust to model changes

topic-sass
Jason Denney 11 years ago
parent
commit
076a59ab45
  1. 3
      db/migrate/20130902201853_add_model_to_bike.rb

3
db/migrate/20130902201853_add_model_to_bike.rb

@ -3,8 +3,7 @@ class AddModelToBike < ActiveRecord::Migration
add_column :bikes, :model, :string
change_column :bikes, :bike_model_id, :integer, :null => true
Bike.all.each do |bike|
bike.model = BikeModel.find_by_id(bike.bike_model_id).model
bike.save
bike.update_attribute(:model, BikeModel.find_by_id(bike['bike_model_id']).model )
end
end
end

Loading…
Cancel
Save