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

Use None criteria instead of $in with empty list in HABTM association

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 9.0.0
    • Affects Version/s: None
    • Component/s: Query
    • None
    • Minor Change

      lib/mongoid/association/referenced/has_and_belongs_to_many.rb has this code:

                crit = relation_class.all_of(primary_key => {"$in" => id_list || []})
      

      When id_list is empty, it seems to me this criteria should be replaced with an instance of None to avoid an unsatisfiable database query.

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

              Created:
              Updated:
              Resolved: