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

Unmask Enumerable#find on one to many associations

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.2.0.rc1
    • Component/s: Query
    • Labels:
    • Release Notes:
      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.
    • Backwards Compatibility:
      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

              Assignee:
              oleg.pudeyev Oleg Pudeyev
              Reporter:
              rgould@u2622.ca Richard Gould
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: