mongodb/mongoid · error · Mongoid::Errors::UnknownModel
Attempted to instantiate an object of the unknown model '%{k
Error message
Attempted to instantiate an object of the unknown model '%{klass}'. What it means
Error "Attempted to instantiate an object of the unknown model '%{klass}'." thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/factory.rb:112
# @return [ Document ] The instantiated document.
def instantiate_with_type(execute_callbacks)
constantized_type.instantiate_document(
attributes, selected_fields,
execute_callbacks: execute_callbacks
)
end
# Retrieve the `Class` instance of the requested type, either by finding it
# in the `klass` discriminator mapping, or by otherwise finding a
# Document model with the given name.
#
# @return [ Mongoid::Document ] the requested Document model
def constantized_type
@constantized_type ||= begin
constantized = klass.get_discriminator_mapping(type) || constantize(type)
# Check if the class is a Document class
raise Errors::UnknownModel.new(camelized, type) unless constantized.respond_to?(:instantiate)
constantized
end
end
# Attempts to convert the argument into a Class object by camelizing
# it and treating the result as the name of a constant.
#
# @param type [ String ] The name of the type to constantize
#
# @raise [ Errors::UnknownModel ] if the argument does not correspond to
# an existing constant.
#
# @return [ Class ] the Class that the type resolves to
def constantize(type)
camelized = type.camelize
camelized.constantize
rescue NameErrorView on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/factory.rb:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23).
Data as JSON: /api/errors/ca5e9571a641bd02.
Report an issue: GitHub.