ruby - How to delete multi column unique index on destroying a record in Rails? -


i working on spreecommerce 3.0.2 app on rails 4.2

spree defines index on spree_shipping_rates table (taken schema.rb file):

add_index "spree_shipping_rates", ["shipment_id", "shipping_method_id"], name:     "spree_shipping_rates_join_index", unique: true, using: :btree 

however, when spree_shipping_rates record destroyed, appears index entry still persists following error when creating the same record again:

pg::uniqueviolation: error:  duplicate key value violates unique constraint "spree_shipping_rates_join_index" detail:  key (shipment_id, shipping_method_id)=(3, 3) exists. 

my questions how can make sure associated unique index removed when spree_shipping_rates record destroyed?

some context:

in spree, when user checking out , enters shipping , billing address , saves, new shipment order created , existing shipments destroyed.

checkout.rb line 95:

if states[:delivery]     before_transition to: :delivery, do: :create_proposed_shipments     .     . end  

order.rb line 474:

def create_proposed_shipments   adjustments.shipping.delete_all   shipments.destroy_all   self.shipments = spree::stock::coordinator.new(self).shipments end 

shipment.rb line 22:

has_many :shipping_rates, -> { order('cost asc') }, dependent: :delete_all 

as can see, associated shipping rates "deleted" when order's shipments destroyed.

does :delete_all in above code block not remove indexes? should :destroy?


Comments