Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5052

Eager loading for referenced associations under embedded documents

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 9.0.0
    • Affects Version/s: 7.1.5
    • Component/s: Query
    • Environment:
      Ruby 2.5.8, Rails 6.0.3.5

      Given the models

      class Family
        include Mongoid::Document
      
        embeds_many :children
      end
      
      class Child
        include Mongoid::Document
      
        embedded_in :family
      
        belongs_to :school
      end
      
      class School
        include Mongoid::Document
      end
      

      I assumed it would be possible to eagerly load the schools of all children in all families, but it threw an exception:

      2.5.8 :004 > Family.all.includes(children: :school).each { |f| p f }
      Traceback (most recent call last):
              1: from (irb):4
      NoMethodError (undefined method `eager_loader' for Mongoid::Association::Embedded::EmbedsMany::Proxy:Class)
      

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            larnold@givve.com Leo Arnold
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: