Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1975

Document.last doesn't take default scope into account

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0.0
    • Component/s: None
    • Labels:
      None

      Description

      Hi,

      I noticed .first orders different than .last. It seems that .last doesn't take default scope into account.

      class Job
        include Mongoid::Document
        include Mongoid::Timestamps
       
        default_scope desc(:created_at)
      end
       
      Job.first 
      # MOPED: 127.0.0.1:27017 QUERY ... 
      #   selector={"$query"=>{}, "$orderby"=>{"created_at"=>-1}} 
      #   flags=[:slave_ok] limit=-1 skip=0 fields=nil (0.0ms) 
      Job.last 
      # MOPED: 127.0.0.1:27017 QUERY ... 
      #   selector={"$query"=>{}, "$orderby"=>{:_id=>-1}} 
      #   flags=[:slave_ok] limit=-1 skip=0 fields=nil (0.0ms) 
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: