From 92536c08d53c5d54f6c526bfdc5d854dd00a7a88 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 24 Jul 2017 15:36:30 -0500 Subject: Document the rest of lib --- lib/active_storage/attached/macros.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/active_storage/attached/macros.rb') diff --git a/lib/active_storage/attached/macros.rb b/lib/active_storage/attached/macros.rb index 11f88f16e5..89297e5bdf 100644 --- a/lib/active_storage/attached/macros.rb +++ b/lib/active_storage/attached/macros.rb @@ -9,6 +9,15 @@ module ActiveStorage::Attached::Macros # There is no column defined on the model side, Active Storage takes # care of the mapping between your records and the attachment. # + # Under the covers, this relationship is implemented as a `has_one` association to a + # `ActiveStorage::Attachment` record and a `has_one-through` association to a + # `ActiveStorage::Blob` record. These associations are available as `avatar_attachment` + # and `avatar_blob`. But you shouldn't need to work with these associations directly in + # most circumstances. + # + # The system has been designed to having you go through the `ActiveStorage::Attached::One` + # proxy that provides the dynamic proxy to the associations and factory methods, like `#attach`. + # # If the +:dependent+ option isn't set, the attachment will be purged # (i.e. destroyed) whenever the record is destroyed. def has_one_attached(name, dependent: :purge_later) @@ -38,6 +47,15 @@ module ActiveStorage::Attached::Macros # # Gallery.where(user: Current.user).with_attached_photos # + # Under the covers, this relationship is implemented as a `has_many` association to a + # `ActiveStorage::Attachment` record and a `has_many-through` association to a + # `ActiveStorage::Blob` record. These associations are available as `photos_attachments` + # and `photos_blobs`. But you shouldn't need to work with these associations directly in + # most circumstances. + # + # The system has been designed to having you go through the `ActiveStorage::Attached::Many` + # proxy that provides the dynamic proxy to the associations and factory methods, like `#attach`. + # # If the +:dependent+ option isn't set, all the attachments will be purged # (i.e. destroyed) whenever the record is destroyed. def has_many_attached(name, dependent: :purge_later) -- cgit v1.2.3