This module handles embedded associations sorting Since mongodb doesn’t have virtual collection for embedded docs yet (see jira.mongodb.org/browse/SERVER-142 for details) Sorting implemented in ruby This can be a performance killer on collections with many embedded documents
Sorts documents
@param [ Array<Documents> ] documents array of documents @param [ Mongoid::Relations::Metadata ] metadata association metadata
# File lib/mongoid/relations/embedded/sort.rb, line 16 def sort_documents!(documents, metadata) sort_options = Criteria.new(metadata.klass).order_by(metadata.order).options[:sort] docs = documents.sort_by do |document| sort_options.map do |key, direction| Contexts::Enumerable::Sort.new(document.read_attribute(key), direction) end end documents.replace(docs) end
Generated with the Darkfish Rdoc Generator 2.