Created
November 23, 2012 13:06
-
-
Save tomash/4135537 to your computer and use it in GitHub Desktop.
fix order addresses #438136
This file contains hidden or 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
# 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}" |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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