diff --git a/core/app/models/concerns/spree/user_methods.rb b/core/app/models/concerns/spree/user_methods.rb index 2aadbce3e2b..f9a38179044 100644 --- a/core/app/models/concerns/spree/user_methods.rb +++ b/core/app/models/concerns/spree/user_methods.rb @@ -8,10 +8,10 @@ module UserMethods include Spree::RansackableAttributes included do - has_many :role_users, class_name: 'Spree::RoleUser', foreign_key: :user_id + has_many :role_users, class_name: 'Spree::RoleUser', foreign_key: :user_id, dependent: :destroy has_many :spree_roles, through: :role_users, class_name: 'Spree::Role', source: :role - has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser' + has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser', dependent: :destroy has_many :promotion_rules, through: :promotion_rule_users, class_name: 'Spree::PromotionRule' has_many :orders, foreign_key: :user_id, class_name: "Spree::Order" diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb index 3bc20432d65..43bb0c35234 100644 --- a/core/app/models/spree/credit_card.rb +++ b/core/app/models/spree/credit_card.rb @@ -2,7 +2,7 @@ module Spree class CreditCard < Spree::Base belongs_to :payment_method belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id' - has_many :payments, as: :source + has_many :payments, as: :source, dependent: :restrict_with_error before_save :set_last_digits diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rb index 4f81079529d..ddcde645bfd 100644 --- a/core/app/models/spree/option_type.rb +++ b/core/app/models/spree/option_type.rb @@ -9,7 +9,7 @@ class OptionType < Spree::Base has_many :products, through: :product_option_types - has_many :option_type_prototypes, class_name: 'Spree::OptionTypePrototype' + has_many :option_type_prototypes, class_name: 'Spree::OptionTypePrototype', dependent: :destroy has_many :prototypes, through: :option_type_prototypes, class_name: 'Spree::Prototype' with_options presence: true do diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 09eb13b1679..3ebe6902c7a 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -96,7 +96,7 @@ class Order < Spree::Base dependent: :destroy, inverse_of: :order - has_many :order_promotions, class_name: 'Spree::OrderPromotion' + has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy has_many :promotions, through: :order_promotions, class_name: 'Spree::Promotion' has_many :shipments, dependent: :destroy, inverse_of: :order do diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb index 1f177ce9149..752a2278995 100644 --- a/core/app/models/spree/payment.rb +++ b/core/app/models/spree/payment.rb @@ -17,8 +17,8 @@ class Payment < Spree::Base belongs_to :source, polymorphic: true has_many :offsets, -> { offset_payment }, class_name: "Spree::Payment", foreign_key: :source_id - has_many :log_entries, as: :source - has_many :state_changes, as: :stateful + has_many :log_entries, as: :source, dependent: :restrict_with_error + has_many :state_changes, as: :stateful, dependent: :restrict_with_error has_many :capture_events, class_name: 'Spree::PaymentCaptureEvent' has_many :refunds, inverse_of: :payment diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index f87cf6c7860..8f8f4cd386c 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -30,10 +30,10 @@ class Product < Spree::Base has_many :product_properties, dependent: :destroy, inverse_of: :product has_many :properties, through: :product_properties - has_many :classifications, dependent: :delete_all, inverse_of: :product + has_many :classifications, dependent: :destroy, inverse_of: :product has_many :taxons, through: :classifications, before_remove: :remove_taxon - has_many :product_promotion_rules, class_name: 'Spree::ProductPromotionRule' + has_many :product_promotion_rules, class_name: 'Spree::ProductPromotionRule', dependent: :destroy has_many :promotion_rules, through: :product_promotion_rules, class_name: 'Spree::PromotionRule' belongs_to :tax_category, class_name: 'Spree::TaxCategory' diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb index fa35c514f8d..613c016663c 100644 --- a/core/app/models/spree/promotion.rb +++ b/core/app/models/spree/promotion.rb @@ -13,7 +13,7 @@ class Promotion < Spree::Base has_many :promotion_actions, autosave: true, dependent: :destroy alias_method :actions, :promotion_actions - has_many :order_promotions, class_name: 'Spree::OrderPromotion' + has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy has_many :orders, through: :order_promotions, class_name: 'Spree::Order' accepts_nested_attributes_for :promotion_actions, :promotion_rules diff --git a/core/app/models/spree/promotion/rules/product.rb b/core/app/models/spree/promotion/rules/product.rb index 80216b1b08d..a10dcf366d2 100644 --- a/core/app/models/spree/promotion/rules/product.rb +++ b/core/app/models/spree/promotion/rules/product.rb @@ -6,7 +6,7 @@ class Promotion module Rules class Product < PromotionRule has_many :product_promotion_rules, class_name: 'Spree::ProductPromotionRule', - foreign_key: :promotion_rule_id + foreign_key: :promotion_rule_id, dependent: :destroy has_many :products, through: :product_promotion_rules, class_name: 'Spree::Product' MATCH_POLICIES = %w(any all none) diff --git a/core/app/models/spree/promotion/rules/taxon.rb b/core/app/models/spree/promotion/rules/taxon.rb index 1165dbbc03b..25c220fd66e 100644 --- a/core/app/models/spree/promotion/rules/taxon.rb +++ b/core/app/models/spree/promotion/rules/taxon.rb @@ -2,7 +2,7 @@ module Spree class Promotion module Rules class Taxon < PromotionRule - has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: 'promotion_rule_id' + has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: 'promotion_rule_id', dependent: :destroy has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon' MATCH_POLICIES = %w(any all) diff --git a/core/app/models/spree/promotion/rules/user.rb b/core/app/models/spree/promotion/rules/user.rb index d8f532b9bd7..4c6946038be 100644 --- a/core/app/models/spree/promotion/rules/user.rb +++ b/core/app/models/spree/promotion/rules/user.rb @@ -5,7 +5,7 @@ class User < PromotionRule belongs_to :user, class_name: "::#{Spree.user_class.to_s}" has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser', - foreign_key: :promotion_rule_id + foreign_key: :promotion_rule_id, dependent: :destroy has_many :users, through: :promotion_rule_users, class_name: "::#{Spree.user_class.to_s}" def applicable?(promotable) diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rb index 650a3e1c860..5fadeb36464 100644 --- a/core/app/models/spree/property.rb +++ b/core/app/models/spree/property.rb @@ -1,9 +1,9 @@ module Spree class Property < Spree::Base - has_many :property_prototypes, class_name: 'Spree::PropertyPrototype' + has_many :property_prototypes, class_name: 'Spree::PropertyPrototype', dependent: :destroy has_many :prototypes, through: :property_prototypes, class_name: 'Spree::Prototype' - has_many :product_properties, dependent: :delete_all, inverse_of: :property + has_many :product_properties, dependent: :destroy, inverse_of: :property has_many :products, through: :product_properties validates :name, :presentation, presence: true diff --git a/core/app/models/spree/prototype.rb b/core/app/models/spree/prototype.rb index b8c504a2dce..775d1f8421d 100644 --- a/core/app/models/spree/prototype.rb +++ b/core/app/models/spree/prototype.rb @@ -1,12 +1,12 @@ module Spree class Prototype < Spree::Base - has_many :property_prototypes, class_name: 'Spree::PropertyPrototype' + has_many :property_prototypes, class_name: 'Spree::PropertyPrototype', dependent: :destroy has_many :properties, through: :property_prototypes, class_name: 'Spree::Property' - has_many :option_type_prototypes, class_name: 'Spree::OptionTypePrototype' + has_many :option_type_prototypes, class_name: 'Spree::OptionTypePrototype', dependent: :destroy has_many :option_types, through: :option_type_prototypes, class_name: 'Spree::OptionType' - has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon' + has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroy has_many :taxons, through: :prototype_taxons, class_name: 'Spree::Taxon' validates :name, presence: true diff --git a/core/app/models/spree/role.rb b/core/app/models/spree/role.rb index 32c22c1b55f..f9ef23d095e 100644 --- a/core/app/models/spree/role.rb +++ b/core/app/models/spree/role.rb @@ -1,6 +1,6 @@ module Spree class Role < Spree::Base - has_many :role_users, class_name: 'Spree::RoleUser' + has_many :role_users, class_name: 'Spree::RoleUser', dependent: :destroy has_many :users, through: :role_users, class_name: Spree.user_class.to_s validates :name, presence: true, uniqueness: { allow_blank: true } diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index a03a514d0e2..5940a6f6ad6 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -13,13 +13,13 @@ class Shipment < Spree::Base end belongs_to :stock_location, class_name: 'Spree::StockLocation' - with_options dependent: :delete_all do + with_options dependent: :destroy do has_many :adjustments, as: :adjustable has_many :inventory_units, inverse_of: :shipment has_many :shipping_rates, -> { order(:cost) } end has_many :shipping_methods, through: :shipping_rates - has_many :state_changes, as: :stateful + has_many :state_changes, as: :stateful, dependent: :restrict_with_error after_save :update_adjustments diff --git a/core/app/models/spree/shipping_category.rb b/core/app/models/spree/shipping_category.rb index fd16b4d23f1..9317ada1615 100644 --- a/core/app/models/spree/shipping_category.rb +++ b/core/app/models/spree/shipping_category.rb @@ -4,7 +4,7 @@ class ShippingCategory < Spree::Base with_options inverse_of: :shipping_category do has_many :products - has_many :shipping_method_categories + has_many :shipping_method_categories, dependent: :destroy end has_many :shipping_methods, through: :shipping_method_categories end diff --git a/core/app/models/spree/shipping_method.rb b/core/app/models/spree/shipping_method.rb index a366b3758ca..bb146f79373 100644 --- a/core/app/models/spree/shipping_method.rb +++ b/core/app/models/spree/shipping_method.rb @@ -13,7 +13,7 @@ class ShippingMethod < Spree::Base has_many :shipping_method_categories, dependent: :destroy has_many :shipping_categories, through: :shipping_method_categories - has_many :shipping_rates, inverse_of: :shipping_method + has_many :shipping_rates, inverse_of: :shipping_method, dependent: :destroy has_many :shipments, through: :shipping_rates has_many :shipping_method_zones, class_name: 'Spree::ShippingMethodZone', diff --git a/core/app/models/spree/stock_location.rb b/core/app/models/spree/stock_location.rb index 62e47229a13..4ac90a1de1c 100644 --- a/core/app/models/spree/stock_location.rb +++ b/core/app/models/spree/stock_location.rb @@ -1,7 +1,7 @@ module Spree class StockLocation < Spree::Base has_many :shipments - has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location + has_many :stock_items, dependent: :destroy, inverse_of: :stock_location has_many :stock_movements, through: :stock_items belongs_to :state, class_name: 'Spree::State' diff --git a/core/app/models/spree/stock_transfer.rb b/core/app/models/spree/stock_transfer.rb index f106ff9b186..38c3fe0de25 100644 --- a/core/app/models/spree/stock_transfer.rb +++ b/core/app/models/spree/stock_transfer.rb @@ -5,7 +5,7 @@ class StockTransfer < Spree::Base extend FriendlyId friendly_id :number, slug_column: :number, use: :slugged - has_many :stock_movements, as: :originator + has_many :stock_movements, as: :originator, dependent: :restrict_with_error belongs_to :source_location, class_name: 'StockLocation' belongs_to :destination_location, class_name: 'StockLocation' diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb index c3b4e997a18..275b40da780 100644 --- a/core/app/models/spree/taxon.rb +++ b/core/app/models/spree/taxon.rb @@ -10,13 +10,13 @@ class Taxon < Spree::Base acts_as_nested_set dependent: :destroy belongs_to :taxonomy, class_name: 'Spree::Taxonomy', inverse_of: :taxons - has_many :classifications, -> { order(:position) }, dependent: :delete_all, inverse_of: :taxon + has_many :classifications, -> { order(:position) }, dependent: :destroy, inverse_of: :taxon has_many :products, through: :classifications - has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon' + has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroy has_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype' - has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon' + has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', dependent: :destroy has_many :promotion_rules, through: :promotion_rule_taxons, class_name: 'Spree::PromotionRule' validates :name, presence: true diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb index 9aa62418e5c..d2a7c8b1b60 100644 --- a/core/spec/models/spree/product_spec.rb +++ b/core/spec/models/spree/product_spec.rb @@ -445,7 +445,7 @@ def build_option_type_with_values(name, values) it "will delete all classifications" do reflection = Spree::Product.reflect_on_association(:classifications) - expect(reflection.options[:dependent]).to eq(:delete_all) + expect(reflection.options[:dependent]).to eq(:destroy) end end diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 23d337cdcbf..4627afe71de 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -716,7 +716,7 @@ def perform() true end context "#destroy" do it "destroys linked shipping_rates" do reflection = Spree::Shipment.reflect_on_association(:shipping_rates) - expect(reflection.options[:dependent]).to be(:delete_all) + expect(reflection.options[:dependent]).to be(:destroy) end end