diff options
Diffstat (limited to 'activestorage/app/models/active_storage/attachment.rb')
-rw-r--r-- | activestorage/app/models/active_storage/attachment.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb index c59877a9a5..bb80799044 100644 --- a/activestorage/app/models/active_storage/attachment.rb +++ b/activestorage/app/models/active_storage/attachment.rb @@ -15,17 +15,18 @@ class ActiveStorage::Attachment < ActiveRecord::Base delegate_missing_to :blob after_create_commit :analyze_blob_later, :identify_blob + after_destroy_commit :purge_dependent_blob_later - # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment. + # Synchronously purges the blob (deletes it from the configured service) and deletes the attachment. def purge blob.purge - destroy + delete end - # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service). + # Deletes the attachment and queues a background job to purge the blob (delete it from the configured service). def purge_later blob.purge_later - destroy + delete end private @@ -36,4 +37,13 @@ class ActiveStorage::Attachment < ActiveRecord::Base def analyze_blob_later blob.analyze_later unless blob.analyzed? end + + def purge_dependent_blob_later + blob.purge_later if dependent == :purge_later + end + + + def dependent + record.attachment_reflections[name]&.options[:dependent] + end end |