Sha256: 709a6f27f431f07123002b61566e73a25c4316ae5daf60faafb806683618ca45
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require "active_support/core_ext/module/delegation" # Attachments associate records with blobs. Usually that's a one record-many blobs relationship, # but it is possible to associate many different records with the same blob. If you're doing that, # you'll want to declare with <tt>has_one/many_attached :thingy, dependent: false</tt>, so that destroying # any one record won't destroy the blob as well. (Then you'll need to do your own garbage collecting, though). class ActiveStorage::Attachment < ActiveRecord::Base self.table_name = "active_storage_attachments" belongs_to :record, polymorphic: true, touch: true belongs_to :blob, class_name: "ActiveStorage::Blob" delegate_missing_to :blob after_create_commit :analyze_blob_later # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment. def purge blob.purge destroy end # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service). def purge_later blob.purge_later destroy end private def analyze_blob_later blob.analyze_later unless blob.analyzed? end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activestorage-5.2.0.beta2 | app/models/active_storage/attachment.rb |
activestorage-5.2.0.beta1 | app/models/active_storage/attachment.rb |