From 180cd4abe6cd76c6a4ab06c5be23c8f5fe0429cf Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Thu, 7 Sep 2023 16:34:07 +0900 Subject: [PATCH] Revert Complicated Rails/HasManyOrHasOneDependent Errors --- app/models/enterprise.rb | 11 +++++------ app/models/spree/address.rb | 2 +- app/models/spree/stock_item.rb | 2 +- app/models/spree/tax_rate.rb | 2 +- app/models/spree/variant.rb | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index d9d41f5d91..bd9aedbc93 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -43,26 +43,25 @@ class Enterprise < ApplicationRecord foreign_key: 'supplier_id', dependent: :destroy has_many :supplied_variants, through: :supplied_products, source: :variants - has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id', - dependent: :nullify + has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id' belongs_to :address, class_name: 'Spree::Address' belongs_to :business_address, optional: true, class_name: 'Spree::Address', dependent: :destroy - has_many :enterprise_fees, dependent: :nullify + has_many :enterprise_fees has_many :enterprise_roles, dependent: :destroy has_many :users, through: :enterprise_roles belongs_to :owner, class_name: 'Spree::User', inverse_of: :owned_enterprises has_many :distributor_payment_methods, - inverse_of: :distributor, foreign_key: :distributor_id, dependent: :destroy + inverse_of: :distributor, foreign_key: :distributor_id has_many :distributor_shipping_methods, - inverse_of: :distributor, foreign_key: :distributor_id, dependent: :destroy + inverse_of: :distributor, foreign_key: :distributor_id has_many :payment_methods, through: :distributor_payment_methods has_many :shipping_methods, through: :distributor_shipping_methods has_many :customers, dependent: :destroy has_many :inventory_items, dependent: :destroy has_many :tag_rules, dependent: :destroy has_one :stripe_account, dependent: :destroy - has_many :vouchers, dependent: :destroy + has_many :vouchers has_one :custom_tab, dependent: :destroy delegate :latitude, :longitude, :city, :state_name, to: :address diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 6ff007e62d..703babb4ee 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -13,7 +13,7 @@ module Spree belongs_to :state, class_name: "Spree::State" has_one :enterprise, dependent: :restrict_with_exception - has_many :shipments, dependent: :nullify + has_many :shipments validates :address1, :city, :country, :phone, presence: true validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank? } diff --git a/app/models/spree/stock_item.rb b/app/models/spree/stock_item.rb index f28cfe7f65..192a154b3d 100644 --- a/app/models/spree/stock_item.rb +++ b/app/models/spree/stock_item.rb @@ -8,7 +8,7 @@ module Spree belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant' - has_many :stock_movements, dependent: :delete_all # delete_all required to avoid ReadOnlyError + has_many :stock_movements validates :stock_location, :variant, presence: true validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] } diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index d7d91a7b73..62dade25b1 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -21,7 +21,7 @@ module Spree belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates belongs_to :tax_category, class_name: "Spree::TaxCategory", inverse_of: :tax_rates - has_many :adjustments, as: :originator, dependent: nil + has_many :adjustments, as: :originator validates :amount, presence: true, numericality: true validates :tax_category, presence: true diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 4fccf0161d..da462602b0 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -33,8 +33,8 @@ module Spree delegate :name, :name=, :description, :description=, :meta_keywords, to: :product - has_many :inventory_units, inverse_of: :variant, dependent: nil - has_many :line_items, inverse_of: :variant, dependent: nil + has_many :inventory_units, inverse_of: :variant + has_many :line_items, inverse_of: :variant has_many :stock_items, dependent: :destroy, inverse_of: :variant has_many :stock_locations, through: :stock_items @@ -54,7 +54,7 @@ module Spree delegate :display_price, :display_amount, :price, :price=, :currency, :currency=, to: :find_or_build_default_price - has_many :exchange_variants, dependent: :destroy + has_many :exchange_variants has_many :exchanges, through: :exchange_variants has_many :variant_overrides, dependent: :destroy has_many :inventory_items, dependent: :destroy