Sha256: 62683edb7dd0c45d9ed799cd0be2df2b2e4b3915e7106d590ddd2a278ced0e92

Contents?: true

Size: 795 Bytes

Versions: 14

Compression:

Stored size: 795 Bytes

Contents

# encoding: utf-8
require "mongoid/association/referenced/eager"

module Mongoid
  module Association

    # This module defines the eager loading behavior for criteria.
    #
    # @since 7.0
    module EagerLoadable

      def eager_loadable?
        !criteria.inclusions.empty?
      end

      def eager_load(docs)
        docs.tap do |d|
          if eager_loadable?
            preload(criteria.inclusions, d)
          end
        end
      end

      def preload(relations, docs)
        relations.group_by(&:inverse_class_name)
            .values
            .each do |associations|
          associations.group_by(&:relation)
              .each do |relation, association|
            relation.eager_loader(association, docs).run
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.12 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.11 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.10 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.8 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.7 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.6 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.5 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.4 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.3 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.2 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.1 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.0 lib/mongoid/association/eager_loadable.rb
mongoid-7.0.0.beta lib/mongoid/association/eager_loadable.rb