{"record":{"id":"ef5c0f475359e41f","repo":"mongodb/mongoid","slug":"through-names-join-are-through-associati","errorCode":null,"errorMessage":"#{through_names.join(', ')} are :through associations and do not support $lookup-based eager loading. All inclusions for this query will be preloaded using separate queries.","messagePattern":"#(.+?) are :through associations and do not support \\$lookup-based eager loading\\. All inclusions for this query will be preloaded using separate queries\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/eager_loadable.rb","lineNumber":60,"sourceCode":"            \"#{offender.name} (client: #{offender.klass.client_name}, database: #{offender.klass.database_name})\"\n          end\n          Mongoid.logger.warn(\n            'eager_load cannot use $lookup aggregation because the following associations ' \\\n            \"reside in a different cluster or database than #{klass} \" \\\n            \"(client: #{klass.client_name}, database: #{klass.database_name}): \" \\\n            \"#{offender_descriptions.join(', ')}. Falling back to #includes behavior.\"\n          )\n          return eager_load(docs_for_lookup_fallback)\n        end\n\n        through_inclusions = criteria.inclusions.select do |association|\n          association.is_a?(Association::Referenced::HasOneThrough) ||\n            association.is_a?(Association::Referenced::HasManyThrough)\n        end\n\n        if through_inclusions.any?\n          through_names = through_inclusions.map { |association| \":#{association.name}\" }\n          Mongoid.logger.warn(\n            \"#{through_names.join(', ')} are :through associations and do not support \" \\\n            '$lookup-based eager loading. All inclusions for this query will be preloaded ' \\\n            'using separate queries.'\n          )\n          return eager_load(docs_for_lookup_fallback)\n        end\n\n        documents = preload_for_lookup(criteria)\n        # A polymorphic belongs_to cannot be expressed as a $lookup: its target\n        # collection varies per document. It is resolved after the roots are\n        # materialized, each inclusion by its own preloader.\n        criteria.inclusions.select(&:polymorphic?).each do |association|\n          EagerLoad::PolymorphicPreloader.new(association, klass).preload_into(documents)\n        end\n        documents\n      end\n\n      # Load the associations for the given documents. This will be done","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/eager_loadable.rb#L42-L78","documentation":"Error \"#{through_names.join(', ')} are :through associations and do not support $lookup-based eager loading. All inclusions for this query will be preloaded using separate queries.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/eager_loadable.rb:60 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}