Revert "Remove delete digitals on soft delete of variant"
This reverts commit d23462fadb.
This commit is contained in:
@@ -1,8 +1,20 @@
|
|||||||
Spree::Variant.class_eval do
|
Spree::Variant.class_eval do
|
||||||
|
|
||||||
has_many :digitals, :dependent => :destroy
|
has_many :digitals, :dependent => :destroy
|
||||||
|
after_save :destroy_digital, :if => :deleted?
|
||||||
|
|
||||||
# Is this variant to be downloaded by the customer?
|
# Is this variant to be downloaded by the customer?
|
||||||
def digital?
|
def digital?
|
||||||
digitals.present?
|
digitals.present?
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user