1
0
mirror of https://github.com/fspc/BikeShed-1.git synced 2025-02-28 08:43:23 -05:00

Make migration robust to model changes

This commit is contained in:
Jason Denney 2013-11-11 17:27:51 -05:00
parent 1075c1a5b3
commit 076a59ab45

View File

@ -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