{"record":{"id":"5d2a8c7565d5b172","repo":"mongodb/mongoid","slug":"self-class-must-implement-docs-for-lookup-fall","errorCode":null,"errorMessage":"#{self.class} must implement #docs_for_lookup_fallback","messagePattern":"#(.+?) must implement #docs_for_lookup_fallback","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/eager_loadable.rb","lineNumber":133,"sourceCode":"      # polymorphic inclusions it leaves out are resolved by the caller.\n      #\n      # @param [ Mongoid::Criteria ] criteria The criteria to load.\n      #\n      # @return [ Array<Mongoid::Document> ] The materialized root documents.\n      def preload_for_lookup(criteria)\n        pipeline = EagerLoad::LookupPipeline.new(criteria).stages\n        Eager.run(criteria.inclusions, [], true, pipeline)\n      end\n\n      private\n\n      # Returns the materialized documents to use when falling back from\n      # $lookup to #includes-style preloading. Must be implemented by each\n      # concrete context class.\n      #\n      # @return [ Array<Mongoid::Document> ] The materialized documents.\n      def docs_for_lookup_fallback\n        raise NotImplementedError, \"#{self.class} must implement #docs_for_lookup_fallback\"\n      end\n\n      # Returns the inclusions whose target class can't be reached by a $lookup\n      # from the root class, which joins only within the same client and database.\n      #\n      # @return [ Array<Mongoid::Association::Relatable> ] The offending inclusions.\n      def inclusions_unreachable_by_lookup\n        # Polymorphic associations have no single resolvable klass and are not\n        # loaded via $lookup, so they are never offenders.\n        criteria.inclusions.reject do |association|\n          association.polymorphic? || reachable_by_lookup?(association.klass)\n        end\n      end\n\n      # Whether a $lookup from a query on the root class can reach the model: it\n      # must live in the same client and database.\n      def reachable_by_lookup?(model)\n        model.client_name == klass.client_name &&","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/eager_loadable.rb#L115-L151","documentation":"Error \"#{self.class} must implement #docs_for_lookup_fallback\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/eager_loadable.rb:133 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"}