Sha256: 50abe095244554f93d195be05b8d1a8762532b7535e158673a72e619a3a58479

Contents?: true

Size: 1.03 KB

Versions: 24

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:
    module Embedded #:nodoc:

      # This module handles embedded associations sorting
      # Since mongodb doesn't have virtual collection for embedded docs yet
      # (see https://jira.mongodb.org/browse/SERVER-142 for details)
      # Sorting implemented in ruby
	    # This can be a performance killer on collections with many embedded documents
	    module Sort

        # Sorts documents
        #
        # @param [ Array<Documents> ] documents array of documents
        # @param [ Mongoid::Relations::Metadata ] metadata association metadata
        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
	    end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
mongoid-multi-db-3.0.0 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.6 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.5 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.5 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.4 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.4 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.3 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.2 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.3 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.1 lib/mongoid/relations/embedded/sort.rb
mongoid-2.3.0 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.2 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.1 lib/mongoid/relations/embedded/sort.rb
mongoid-2.2.0 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.9 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.8 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.7 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.6 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.5 lib/mongoid/relations/embedded/sort.rb
mongoid-2.1.4 lib/mongoid/relations/embedded/sort.rb