{"record":{"id":"e10fe2b2ce46bc54","repo":"mongodb/mongoid","slug":"errors-invalidincludes-new-klass-relation","errorCode":null,"errorMessage":"Errors::InvalidIncludes.new(klass, [ relation ])","messagePattern":"Errors::InvalidIncludes\\.new\\(klass, \\[ relation \\]\\)","errorType":"exception","errorClass":"Mongoid::Errors::InvalidIncludes","httpStatus":null,"severity":"error","filePath":"lib/mongoid/criteria/includable.rb","lineNumber":144,"sourceCode":"      #\n      # @return [ Array<Mongoid::Association::Relatable> ] Matching associations.\n      def resolve_inclusion_associations(parent_class, relation, is_eager_load)\n        if association = parent_class.reflect_on_association(relation)\n          return [ association ]\n        end\n\n        return [] unless is_eager_load\n\n        parent_class.descendants.filter_map { |sub| sub.reflect_on_association(relation) }\n      end\n    end\n\n    def raise_eager_error(is_eager_load, klass, relation)\n      if is_eager_load\n        raise ArgumentError, \"Eager loading only supports arguments that are the names of associations on #{klass}\"\n      end\n\n      raise Errors::InvalidIncludes.new(klass, [ relation ])\n    end\n  end\nend\n","sourceCodeStart":126,"sourceCodeEnd":148,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/criteria/includable.rb#L126-L148","documentation":"Includes validation for the non-eager path: the relation name given to includes does not resolve to an association on the class, so the inclusion cannot be set up and InvalidIncludes is raised naming the offending relation.","triggerScenarios":"Thrown at lib/mongoid/criteria/includable.rb:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a declared association name in includes","Inspect Model.relations to find the correct association names"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","contentChangedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}