1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/active_vault/attachment.rb
David Heinemeier Hansson b7cc003aa0 Attached one and many
2017-07-05 16:09:41 +02:00

26 lines
537 B
Ruby

require "active_vault/blob"
require "global_id"
require "active_support/core_ext/module/delegation"
# Schema: id, record_gid, blob_id, created_at
class ActiveVault::Attachment < ActiveRecord::Base
self.table_name = "active_vault_attachments"
belongs_to :blob, class_name: "ActiveVault::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
end