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

Operator methods overwrite previous conditions

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.5.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible

      When an operator method is called repeatedly it overwrites the previous conditions of the same method. The new conditions should be added to the existing ones.

      Current behavior:

      irb(main):024:0> c=Person.gt(age: 2).gt(age: 1); c
      => 
      #<Mongoid::Criteria
        selector: {"age"=>{"$gt"=>1}}
        options:  {}
        class:    Person
        embedded: false>
      

      Expected something like:

      => 
      #<Mongoid::Criteria
        selector: {"age"=>{"$gt"=>2}, "$and"=>[{"age"=>{"$gt"=>1}}]}
        options:  {}
        class:    Person
        embedded: false>
      

            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: