Module: ActiveRecord::Railties::CollectionCacheAssociationLoading

Defined in:
activerecord/lib/active_record/railties/collection_cache_association_loading.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#collection_with_templateObject



28
29
30
31
# File 'activerecord/lib/active_record/railties/collection_cache_association_loading.rb', line 28

def collection_with_template(*)
  @relation.preload_associations(@collection) if @relation
  super
end

#collection_without_templateObject



23
24
25
26
# File 'activerecord/lib/active_record/railties/collection_cache_association_loading.rb', line 23

def collection_without_template(*)
  @relation.preload_associations(@collection) if @relation
  super
end

#relation_from_options(cached: nil, partial: nil, collection: nil, **_) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'activerecord/lib/active_record/railties/collection_cache_association_loading.rb', line 12

def relation_from_options(cached: nil, partial: nil, collection: nil, **_)
  return unless cached

  relation = partial if partial.is_a?(ActiveRecord::Relation)
  relation ||= collection if collection.is_a?(ActiveRecord::Relation)

  if relation && !relation.loaded?
    relation.skip_preloading!
  end
end

#setup(context, options, as, block) ⇒ Object



6
7
8
9
10
# File 'activerecord/lib/active_record/railties/collection_cache_association_loading.rb', line 6

def setup(context, options, as, block)
  @relation = relation_from_options(**options)

  super
end