Skip to content

Commit b2d35c4

Browse files
authored
Merge pull request rails#42477 from ghiculescu/document-as-eager-loads
Document Active Storage & Action Text eager loading
2 parents 051b0fc + 1c11237 commit b2d35c4

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

actiontext/lib/action_text/attribute.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Attribute
2424
#
2525
# Message.all.with_rich_text_content # Avoids N+1 queries when you just want the body, not the attachments.
2626
# Message.all.with_rich_text_content_and_embeds # Avoids N+1 queries when you just want the body and attachments.
27+
# Message.all.with_all_rich_text # Loads all rich text associations.
2728
#
2829
# === Options
2930
#

activestorage/app/models/active_storage/attachment.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
# on the attachments table prevents blobs from being purged if they’re still attached to any records.
88
#
99
# Attachments also have access to all methods from {ActiveStorage::Blob}[rdoc-ref:ActiveStorage::Blob].
10+
#
11+
# If you wish to preload attachments or blobs, you can use these scopes:
12+
#
13+
# # preloads attachments, their corresponding blobs, and variant records (if using `ActiveStorage.track_variants`)
14+
# User.all.with_attached_avatars
15+
#
16+
# # preloads blobs and variant records (if using `ActiveStorage.track_variants`)
17+
# User.first.avatars.with_all_variant_records
1018
class ActiveStorage::Attachment < ActiveStorage::Record
1119
self.table_name = "active_storage_attachments"
1220

activestorage/app/models/active_storage/blob/representable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module ActiveStorage::Blob::Representable
1212
has_one_attached :preview_image
1313
end
1414

15-
# Returns an ActiveStorage::Variant instance with the set of +transformations+ provided. This is only relevant for image
16-
# files, and it allows any image to be transformed for size, colors, and the like. Example:
15+
# Returns an ActiveStorage::Variant or ActiveStorage::VariantWithRecord instance with the set of +transformations+ provided.
16+
# This is only relevant for image files, and it allows any image to be transformed for size, colors, and the like. Example:
1717
#
1818
# avatar.variant(resize_to_limit: [100, 100]).processed.url
1919
#

activestorage/app/models/active_storage/variant_with_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# Like an ActiveStorage::Variant, but keeps detail about the variant in the database as an
4+
# ActiveStorage::VariantRecord. This is only used if `ActiveStorage.track_variants` is enabled.
35
class ActiveStorage::VariantWithRecord
46
attr_reader :blob, :variation
57

0 commit comments

Comments
 (0)