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

Make all #first and #last methods have consistent signatures and compatible with Ruby core/AR

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 8.0.1, 7.5.0
    • Query
    • Major Change

    Description

      After MONGOID-4547 is implemented, the :id_sort option on first/last should be deprecated (and dropped support for later), and any unsorted taking of documents should use the #take method.

      This ticket is for deprecating in 7.5 and removing support for in 8.0 the id_sort option.

      This ticket will also be used to investigate our current implementation of the limit option, document it, and verify that it's not subject to the same errors the id_sort method was. If necessary, this option can be implemented here as well.
      ------

      #first and #last methods on associations/enumerations are defined in several classes/modules in Mongoid, and are also used from several call sites. It appears that not all method definitions support the same signature that Mongoid itself uses elsewhere. While this may not be an issue for what Mongoid does internally, users that perform the set of operations that Mongoid does generally support on all of the associations/enumerables may run into problems when the call tree path they end up constructing results in Mongoid passing first/last arguments to implementations that don't recognize the arguments.

      For this ticket, all internal uses of first/last by Mongoid should agree on the expected signature.


      Original report:

      In this commit arguments was added in Mongoid::Contextual::Mongo#first and Mongoid::Contextual::Mongo#last. We can't pass arguments in other contexts, like Mongoid::Contextual::None#first.

      In this other commit, arguments was added in Mongoid::Contextual::Memory#first but not in Mongoid::Contextual::Memory#last.

       

      For consistency, is it better to allow arguments for last and first in every context?

      Attachments

        Issue Links

          Activity

            People

              neil.shweky@mongodb.com Neil Shweky (Inactive)
              guirec.corbel@gmail.com Guirec Corbel
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: