Module: ActiveStorage::Attached::Model

Included in:
ActiveRecord::Base
Defined in:
lib/solargraph/rails/annotations/active_storage.rb

Class Method Summary collapse

Class Method Details

.attachment_changesvoid

This method returns an undefined value.



103
# File 'lib/solargraph/rails/annotations/active_storage.rb', line 103

def self.attachment_changes(); end

.changed_for_autosave?Boolean

Returns:

  • (Boolean)


106
# File 'lib/solargraph/rails/annotations/active_storage.rb', line 106

def self.changed_for_autosave?; end

.has_many_attached(name, dependent: :default, service: nil, strict_loading: false) ⇒ void

This method returns an undefined value.

Specifies the relation between multiple attachments and the model.

class Gallery < ApplicationRecord
  has_many_attached :photos
end

There are no columns defined on the model side, Active Storage takes care of the mapping between your records and the attachments.

To avoid N+1 queries, you can include the attached blobs in your query like so:

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.

If you need the attachment to use a service which differs from the globally configured one, pass the :service option. For instance:

class Gallery < ActiveRecord::Base
  has_many_attached :photos, service: :s3
end

If you need to enable strict_loading to prevent lazy loading of attachments, pass the :strict_loading option. You can do:

class Gallery < ApplicationRecord
  has_many_attached :photos, strict_loading: true
end

Parameters:

  • name (String, Symbol)
  • dependent (Symbol) (defaults to: :default)

    the action to take on the attachment when the record is destroyed

  • strict_loading (Boolean) (defaults to: false)
  • service (String, Symbol, nil) (defaults to: nil)

    the service to use for the attachment



100
# File 'lib/solargraph/rails/annotations/active_storage.rb', line 100

def self.has_many_attached(name, dependent: :default, service: nil, strict_loading: false); end

.has_one_attached(name, dependent: :default, service: nil, strict_loading: false) ⇒ void

This method returns an undefined value.

Parameters:

  • name (String, Symbol)
  • dependent (Symbol) (defaults to: :default)

    the action to take on the attachment when the record is destroyed

  • strict_loading (Boolean) (defaults to: false)
  • service (String, Symbol, nil) (defaults to: nil)

    the service to use for the attachment



54
# File 'lib/solargraph/rails/annotations/active_storage.rb', line 54

def self.has_one_attached(name, dependent: :default, service: nil, strict_loading: false); end

.reload(lock = false) ⇒ self

Parameters:

  • lock (BasicObject) (defaults to: false)

Returns:

  • (self)


110
# File 'lib/solargraph/rails/annotations/active_storage.rb', line 110

def self.reload(lock = false); end