From 7c9bc58a4b2433d828117f233f7b4a2f5eba6ce1 Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Fri, 1 Sep 2023 09:21:26 +0900 Subject: [PATCH] Add nullify to orders relationship, instead of manually nullifying --- app/models/customer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 10f171e2b1..a60c0d8013 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -16,7 +16,7 @@ class Customer < ApplicationRecord belongs_to :enterprise belongs_to :user, class_name: "Spree::User", optional: true - has_many :orders, class_name: "Spree::Order", dependent: :destroy + has_many :orders, class_name: "Spree::Order", dependent: :nullify before_validation :downcase_email before_validation :empty_code before_create :associate_user @@ -70,6 +70,5 @@ class Customer < ApplicationRecord throw :abort end Subscription.where(customer_id: id).destroy_all - orders.update_all(customer_id: nil) end end