Module: Mongoid::Relations::Embedded::Sort
- Included in:
- Builders::Embedded::Many
- Defined in:
- lib/mongoid/relations/embedded/sort.rb
Overview
This can be a performance killer on collections with many embedded documents
Instance Method Summary collapse
-
#sort_documents!(documents, metadata) ⇒ Object
Sorts documents.
Instance Method Details
#sort_documents!(documents, metadata) ⇒ Object
Sorts documents
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongoid/relations/embedded/sort.rb', line 17 def sort_documents!(documents, ) = Criteria.new(.klass).order_by(.order).[:sort] docs = documents.sort_by do |document| .map do |key, direction| Contexts::Enumerable::Sort.new(document.read_attribute(key), direction) end end documents.replace(docs) end |