Created
February 19, 2013 12:38
-
-
Save detomastah/4985534 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
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