Skip to content

Instantly share code, notes, and snippets.

@tomash
Created November 23, 2012 13:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomash/4135537 to your computer and use it in GitHub Desktop.
Save tomash/4135537 to your computer and use it in GitHub Desktop.
fix order addresses #438136
# sanity checking
users_with_multiple_addresses = []
User.all.each do |user|
addresses = Address.where(:addressable_type => 'User', :addressable_id => user.id)
if(addresses.count > 1)
users_with_multiple_addresses << user
end
end
puts "Users with multiple addresses: #{users_with_multiple_addresses.map(&:id).inspect}"
# assign order addresses to orders (not users they're cloned from)
# fixed for new orders in #438136
Order.all.each do |o|
if(o.billing_address.present?)
o.billing_address.addressable = o
o.billing_address.save
end
if(o.shipping_address.present?)
o.shipping_address.addressable = o
o.shipping_address.save
end
end
# sanity check: see the other file
orders_without_billing_address = Order.all.find_all{|o| o.billing_address.blank?}.size
orders_without_shipping_address = Order.all.find_all{|o| o.shipping_address.blank?}.size
users_without_address = User.all.find_all{|u| u.address.blank?}.size
puts "orders_without_billing_address = #{orders_without_billing_address}"
puts "orders_without_shipping_address = #{orders_without_shipping_address}"
puts "users_without_address = #{users_without_address}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment