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

Skip eager loading query if all keys are nil

      Let's say we have a "seats" collection and seats can optionally belong to a user. If we query all the seats and eager load the users, but none of the seats actually belong to a user, Mongoid will still query the database for users where the id is

      {"$in"=>[nil]}

      . I see something like this in the logs: {"find"=>"users", "filter"=>{"_id"=>{"$in"=>[nil]}}...

      This change will skip the trip to the db if all the foreign keys are nil.

      Submitted PR: https://github.com/mongodb/mongoid/pull/4621

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: