mongodb/mongoid · error · NotImplementedError
NotImplementedError
Error message
NotImplementedError
What it means
Abstract-method sentinel in the eager loading base class: Eager#preload must be implemented by each concrete eager-loadable subclass. The base implementation exists only to fail loudly when a subclass forgets to define its preload strategy.
Solutions
- Implement #preload in the eager-loading subclass for the association type
- Do not call Eager#preload on the abstract base class
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at lib/mongoid/association/eager.rb:69 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/27981ccfeb1d9fb4.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/association/eager.rb:69
end
while shift_association
preload
@loaded << @docs.collect { |d| d.send(@association.name) if d.respond_to?(@association.name) }
end
@loaded.flatten
end
protected
# Preload the current association.
#
# This method should be implemented in the subclass
#
# @example Preload the current association into the documents.
# loader.preload
def preload
raise NotImplementedError
end
# Preload the current association using $lookup aggregation.
# This method executes the aggregation pipeline
# and instantiates the documents.
# @example Preload the current association using $lookup.
# loader.preload_with_lookup
def preload_with_lookup
# For $lookup aggregation, execute pipeline and instantiate documents
owner_class = @associations.first.owner_class
aggregated_docs = owner_class.collection.aggregate(@pipeline)
aggregated_docs.each do |doc|
parsed_doc = Factory.from_db(owner_class, doc)
@docs << parsed_doc
end
end
# Retrieves the documents referenced by the association, andView on GitHub (pinned to 0da0e23d71)