1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/app/models/active_storage/attachment.rb
David Heinemeier Hansson d50679f4ee Move models and jobs to the app setup
Follow engine conventions more closely
2017-07-22 09:47:24 -05:00

30 lines
618 B
Ruby

require "active_storage/blob"
require "global_id"
require "active_support/core_ext/module/delegation"
# Schema: id, record_gid, blob_id, created_at
class ActiveStorage::Attachment < ActiveRecord::Base
self.table_name = "active_storage_attachments"
belongs_to :blob, class_name: "ActiveStorage::Blob"
delegate_missing_to :blob
def record
@record ||= GlobalID::Locator.locate(record_gid)
end
def record=(record)
@record = record
self.record_gid = record&.to_gid
end
def purge
blob.purge
destroy
end
def purge_later
ActiveStorage::PurgeJob.perform_later(self)
end
end