I'm splitting out some data from a model into a new one and creating an association between them.
I've added the new_model_id
to OldModel
, created NewModel
with address
as a string attribute, and have the following migrations:
class RemoveAddressFromOldModel < ActiveRecord::Migration
def up
OldModel.where("address IS NOT NULL AND address != ''").each do |i|
j = NewModel.create(address: i.address)
i.new_model_id = j.id
i.save
end
remove_column :old_models, :address
end
def down
add_column :old_models, :address, :string
end
end
While the NewModel.create
is working perfectly and getting the right data, the i.save
doesn't seem to be working, as old_models.new_model_id
isn't being populated.
What am I missing with this?