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

Eager loading does not work for belongs_to with STI

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.9, 8.1.9, 9.0.5
    • Affects Version/s: 8.0.1, 8.1.8
    • Component/s: None
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Hi, after upgrading Mongoid to 8.1, eager-loading doesn't work for me in this case:

       
      class Channel
        belongs_to :organization
      end
      class ManagerChannel < Channel; end
       
      Channel.includes(:organization).map(&:organization) # works
      Channel.where(_type: 'ManagerChannel').includes(:organization).map(&:organization) # works
      ManagerChannel.includes(:organization).map(&:organization) # doesn't work (n+1 queries)
       
      I have another model with the same behavior.
      I'm on 8.1.8, but can reproduce it on 8.0.1 too.

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            stanley90x Marek Stanczyk
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None