Skip to content

Instantly share code, notes, and snippets.

@detomastah
Created February 19, 2013 12:38
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save detomastah/4985534 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.transaction do
orders_to_fix = Order.joins(:billing_address).where("orders.billing_address_id = addresses.id AND addresses.addressable_type = 'User'")
orders_to_fix.each do |order|
billing_address = order.build_billing_address order.billing_address.attributes_for_clone
billing_address.addressable = order
billing_address.save(:validate => false)
ActiveRecord::Base.connection.execute("UPDATE orders SET billing_address_id = #{billing_address.id} WHERE id = #{order.id}")
end
end;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment