Skip to content

Commit

Permalink
Merge pull request #48627 from p8/activestorage/document-with-attached
Browse files Browse the repository at this point in the history
Document generated scopes for `has_one_attached` and `has_many_attached`
  • Loading branch information
p8 committed Jul 3, 2023
2 parents d867313 + a2ead3a commit 5694f1e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions activestorage/lib/active_storage/attached/model.rb
Expand Up @@ -9,6 +9,48 @@ module ActiveStorage
module Attached::Model
extend ActiveSupport::Concern

##
# :method: *_attachment
#
# Returns the attachment for the +has_one_attached+.
#
# User.last.avatar_attachment

##
# :method: *_attachments
#
# Returns the attachments for the +has_many_attached+.
#
# Gallery.last.photos_attachments

##
# :method: *_blob
#
# Returns the blob for the +has_one_attached+ attachment.
#
# User.last.avatar_blob

##
# :method: *_blobs
#
# Returns the blobs for the +has_many_attached+ attachments.
#
# Gallery.last.photos_blobs

##
# :method: with_attached_*
#
# Includes the attached blobs in your query to avoid N+1 queries.
#
# If +ActiveStorage.track_variants+ is enabled, it will also include the
# variants record and their attached blobs.
#
# User.with_attached_avatar
#
# Use the plural form for +has_many_attached+:
#
# Gallery.with_attached_photos

class_methods do
# Specifies the relation between a single attachment and the model.
#
Expand Down

0 comments on commit 5694f1e

Please sign in to comment.