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

Unmask Enumerable#find on one to many associations

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 7.2.0.rc1
    • Query
    • Hide
      When calling #find on an association with a block, the call will be delegated to Enumerable#find to filter the documents in the application process space rather than invoking Mongoid::Criteria::Findable#find without arguments.
      Show
      When calling #find on an association with a block, the call will be delegated to Enumerable#find to filter the documents in the application process space rather than invoking Mongoid::Criteria::Findable#find without arguments.
    • Minor Change

    Description

      I found myself on the console today trying to debug an issue by looking at mongoid documents:

      $ items.find { |item| item["uuid"] == "1234" }
      => nil
      $ items.select { |item| item["uuid"] == "1234" }.any?
      => true
      

      In this case, `items` is an instance of `Mongoid::Criteria`, and the `find` being executed was `Mongoid::Criteria::Findable#find`, rather than the `Enumerable#find` which I expected. (Items is defined in another method, in another file, elsewhere, so I had forgotten it was a `Mongoid::Criteria` rather than simply an Enumerable)

      I propose that we add a `Mongoid::Criteria#find` which routes to the appropriate find method based on the passed arguments

      Attachments

        Issue Links

          Activity

            People

              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              rgould@u2622.ca Richard Gould
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: