lib/mongoid/contextual/mongo.rb in mongoid-6.0.2 vs lib/mongoid/contextual/mongo.rb in mongoid-6.0.3
- old
+ new
@@ -668,10 +668,11 @@
# @return [ Array<Document>, Mongo::Collection::View ] The docs to iterate.
#
# @since 3.0.0
def documents_for_iteration
return documents if cached? && !documents.empty?
+ return view unless eager_loadable?
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria.options[:fields]) }
eager_load(docs)
end
# Yield to the document.
@@ -685,11 +686,13 @@
#
# @param [ Document ] document The document to yield to.
#
# @since 3.0.0
def yield_document(document, &block)
- yield(document)
- documents.push(document) if cacheable?
+ doc = document.respond_to?(:_id) ?
+ document : Factory.from_db(klass, document, criteria.options[:fields])
+ yield(doc)
+ documents.push(doc) if cacheable?
end
end
end
end