Sha256: f59aa1893273e1b62da62f6806fe269d5951577718ff74b07dd849938100b977

Contents?: true

Size: 441 Bytes

Versions: 34

Compression:

Stored size: 441 Bytes

Contents

module Mongoid
  class Criteria
    def find_ordered(*ids)
      ids = Array(ids).flatten
      return [] if ids.blank?

      unsorted = any_in(id: ids).to_a
      ids.map { |id| unsorted.detect { |p| p.id.to_s == id.to_s } }.compact
    end
  end
end

module Mongoid
  module FindOrdered
    def find_ordered(*args)
      criteria.find_ordered(*args)
    end
  end
end

Mongoid::Document::ClassMethods.send(:include, Mongoid::FindOrdered)

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.44 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.43 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.42 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.41 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.40 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.39 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.38 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.37 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.36 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.35 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.34 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.33 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.32 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.31 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.30 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.29 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.28 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.27 lib/workarea/ext/mongoid/find_ordered.rb
workarea-core-3.4.26 lib/workarea/ext/mongoid/find_ordered.rb