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

Mongoid::Criteria #with returns klass, which negates the selector

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.11
    • Affects Version/s: None
    • Component/s: None

      # Will return the number of users named Jon
      User.with(:session => :replica_set).where(:first_name => "Jon").count()
      
      # Will return User.count
      User.where(:first_name => "Jon").with(:session => :replica_set).count()
      

      Because Mongoid::Criteria's #with returns klass, the selector and options are negated. If the intention is to always call klass.with({}).where({}), then #with should be removed from Mongoid::Criteria to avoid mistakes that could lead to accidental massive updates, deletions, or long-running queries. Otherwise, #with should return the criteria.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: