mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Restrict deletion of address explicitely
Enterprises have an `address_id` which must point to a valid `Spree::Address`. As Rubocop suggested, I restricted the deletion of addresses when they are still associated to an enterprise. Without declaring `dependent: :restrict`, trying to delete the address would raise `ActiveRecord::InvalidForeignKey`. Now it is more specific and raises `ActiveRecord::DeleteRestrictionError`. I didn't find code rescuing the InvalidForeignKey when deleting addresses. I actually think that we never delete addresses. So this change should not have any impact on the execution.
This commit is contained in:
@@ -1440,7 +1440,6 @@ Rails/HasManyOrHasOneDependent:
|
||||
- 'app/models/customer.rb'
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/order_cycle.rb'
|
||||
- 'app/models/spree/address_decorator.rb'
|
||||
- 'app/models/spree/adjustment_decorator.rb'
|
||||
- 'app/models/spree/order_decorator.rb'
|
||||
- 'app/models/spree/payment_method_decorator.rb'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Spree::Address.class_eval do
|
||||
has_one :enterprise
|
||||
has_one :enterprise, dependent: :restrict
|
||||
belongs_to :country, class_name: "Spree::Country"
|
||||
|
||||
after_save :touch_enterprise
|
||||
|
||||
Reference in New Issue
Block a user