aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/attached/macros.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/lib/active_storage/attached/macros.rb')
-rw-r--r--activestorage/lib/active_storage/attached/macros.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activestorage/lib/active_storage/attached/macros.rb b/activestorage/lib/active_storage/attached/macros.rb
index 2b38a9b887..c51efa9d6b 100644
--- a/activestorage/lib/active_storage/attached/macros.rb
+++ b/activestorage/lib/active_storage/attached/macros.rb
@@ -38,13 +38,13 @@ module ActiveStorage
end
CODE
- has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record
+ has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record, inverse_of: :record
has_one :"#{name}_blob", through: :"#{name}_attachment", class_name: "ActiveStorage::Blob", source: :blob
scope :"with_attached_#{name}", -> { includes("#{name}_attachment": :blob) }
if dependent == :purge_later
- before_destroy { public_send(name).purge_later }
+ after_destroy_commit { public_send(name).purge_later }
end
end
@@ -83,13 +83,13 @@ module ActiveStorage
end
CODE
- has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment"
+ has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record
has_many :"#{name}_blobs", through: :"#{name}_attachments", class_name: "ActiveStorage::Blob", source: :blob
scope :"with_attached_#{name}", -> { includes("#{name}_attachments": :blob) }
if dependent == :purge_later
- before_destroy { public_send(name).purge_later }
+ after_destroy_commit { public_send(name).purge_later }
end
end
end