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

Mongoid::Contextual#last modifies the sort on the view

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Minor Change

      When calling #last on a context, the view within the context is modified to have the reverse _id sorting. The same is not true in #first, and I think this should be changed.

      https://github.com/mongodb/mongoid/blob/064293d2de71ed5d368f789ff2b239495d305027/lib/mongoid/contextual/mongo.rb#L674

      This is causing calling #first after #last to behave unexpectedly:

      context.first # first doc
      context.last # last doc
      context.first # last doc
      

      Additionally #last attempts to get the sort from the criteria, and not from the view, like first does. I think this should be made consistent. Note that when creating a context from a criteria that has a sort, the sort is also transferred to the view.

      We have two options:
      1) change #first to get the sort from the criteria
      2) change #last to not modify the view

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: