Fix Rails/HasManyOrHasOneDependent with delete_all

This commit is contained in:
Neal Chambers
2023-08-25 00:01:55 +09:00
parent 070d2cb855
commit 019b54ea95

View File

@@ -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: :destroy
has_many :stock_movements, dependent: :delete_all # delete_all required to avoid ReadOnlyError
validates :stock_location, :variant, presence: true
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }