From c5b1b876171eddcb43ee2699ce5630c978a01299 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Mon, 29 Oct 2012 11:10:06 -0400 Subject: [PATCH] Revert "Remove delete digitals on soft delete of variant" This reverts commit d23462fadb5ef049b9ed4f667bd405e343c654b1. --- app/models/spree/variant_decorator.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index f589dda..6a17d57 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -1,8 +1,20 @@ Spree::Variant.class_eval do + has_many :digitals, :dependent => :destroy + after_save :destroy_digital, :if => :deleted? # Is this variant to be downloaded by the customer? def digital? digitals.present? end + + private + + # Spree never deleted Digitals, that's why ":dependent => :destroy" won't work on Digital. + # We need to delete the Digital manually here as soon as the Variant is nullified. + # Otherwise you'll have orphan Digitals (and their attached files!) associated with unused Variants. + def destroy_digital + digitals.map &:destroy + end + end