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

find {} does not work on has_many relations

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 7.3.2
    • Affects Version/s: None
    • Component/s: None
    • None

      PR: https://github.com/mongodb/mongoid/pull/5012

      Since #4817 find can take a block, however this is not used when a has many relation proxy is used. This is a simple change to allow the block to be passed through to the criteria.

      Example:

      class Widget 
        include Mongoid::Document
        has_many :screws
      
        def find_flat_screw 
          screws.find { |screw| screw.head == 'flat' } 
        end
      end
      

      The find method above will currently return an empty set incorrectly, instead of the first item in the has_many collection

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            mongodb@mobile-technology.com.au Brad Rees
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: