Sha256: 060df96b0865a6d84e9bfbc87335d63bb21b140e7360b78f257340afd5d4a635

Contents?: true

Size: 887 Bytes

Versions: 16

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Railties # :nodoc:
    module CollectionCacheAssociationLoading #:nodoc:
      def setup(context, options, as, block)
        @relation = relation_from_options(options)

        super
      end

      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

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

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

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
activerecord-6.0.2.2 lib/active_record/railties/collection_cache_association_loading.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.2.1/lib/active_record/railties/collection_cache_association_loading.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/activerecord-6.0.2.1/lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.2.1 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.2 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.2.rc2 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.2.rc1 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.1 lib/active_record/railties/collection_cache_association_loading.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.0/lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.1.rc1 lib/active_record/railties/collection_cache_association_loading.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.0/lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.0 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.0.rc2 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.0.rc1 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.0.beta3 lib/active_record/railties/collection_cache_association_loading.rb
activerecord-6.0.0.beta2 lib/active_record/railties/collection_cache_association_loading.rb