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

Unmask Enumerable#find on one to many associations

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0.rc1
    • Affects Version/s: None
    • Component/s: 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

      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

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

              Created:
              Updated:
              Resolved: