{"record":{"id":"ca5e9571a641bd02","repo":"mongodb/mongoid","slug":"attempted-to-instantiate-an-object-of-the-unknown","errorCode":null,"errorMessage":"Attempted to instantiate an object of the unknown model '%{klass}'.","messagePattern":"Attempted to instantiate an object of the unknown model '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::UnknownModel","httpStatus":null,"severity":"error","filePath":"lib/mongoid/factory.rb","lineNumber":112,"sourceCode":"      # @return [ Document ] The instantiated document.\n      def instantiate_with_type(execute_callbacks)\n        constantized_type.instantiate_document(\n          attributes, selected_fields,\n          execute_callbacks: execute_callbacks\n        )\n      end\n\n      # Retrieve the `Class` instance of the requested type, either by finding it\n      # in the `klass` discriminator mapping, or by otherwise finding a\n      # Document model with the given name.\n      #\n      # @return [ Mongoid::Document ] the requested Document model\n      def constantized_type\n        @constantized_type ||= begin\n          constantized = klass.get_discriminator_mapping(type) || constantize(type)\n\n          # Check if the class is a Document class\n          raise Errors::UnknownModel.new(camelized, type) unless constantized.respond_to?(:instantiate)\n\n          constantized\n        end\n      end\n\n      # Attempts to convert the argument into a Class object by camelizing\n      # it and treating the result as the name of a constant.\n      #\n      # @param type [ String ] The name of the type to constantize\n      #\n      # @raise [ Errors::UnknownModel ] if the argument does not correspond to\n      #   an existing constant.\n      #\n      # @return [ Class ] the Class that the type resolves to\n      def constantize(type)\n        camelized = type.camelize\n        camelized.constantize\n      rescue NameError","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/factory.rb#L94-L130","documentation":"Error \"Attempted to instantiate an object of the unknown model '%{klass}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/factory.rb:112 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"}