Exception: Mongoid::Errors::UnregisteredClass
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
MongoidError ,
StandardError
|
|
Instance Chain:
self,
MongoidError ,
StandardError
|
|
Inherits: |
Mongoid::Errors::MongoidError
|
Defined in: | lib/mongoid/errors/unregistered_class.rb |
Overview
Raised when ::Mongoid
tries to query the identifier to use for a given class in a polymorphic association, but the class has not previously been registered by resolver that was used for the query.
Here’s an exammple:
class Department
include Mongoid::Document
has_many :managers, as: :unit
end
class Manager
include Mongoid::Document
belongs_to :unit, polymorphic: :org
end
The Manager class is configured to use a custom resolver named :org
when resolving the polymorphic unit
association. However, the Department
class is not registered with that resolver. When the program tries to associate a manager record with a department, it will not be able to find the required key in the :org
resolver, and will fail with this exception.
The solution is to make sure the Department
class is properly registered with the :org
resolver:
class Department
include Mongoid::Document
identify_as resolver: :org
has_many :managers, as: :unit
end
Constant Summary
MongoidError
- Inherited
Class Method Summary
- .new(klass, resolver) ⇒ UnregisteredClass constructor
Instance Attribute Summary
MongoidError
- Inherited
Instance Method Summary
MongoidError
- Inherited
#compose_message | Compose the message. |
#translate | Given the key of the specific error and the options hash, translate the message. |
#translate_problem | Create the problem. |
#translate_resolution | Create the resolution. |
#translate_summary | Create the summary. |
Constructor Details
.new(klass, resolver) ⇒ UnregisteredClass
# File 'lib/mongoid/errors/unregistered_class.rb', line 36
def initialize(klass, resolver) super( ( 'unregistered_class', klass: klass, resolver: resolver.inspect ) ) end