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

Require criteria methods be provided arguments

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0.rc0
    • Affects Version/s: None
    • Component/s: Query
    • None

      Mongoid currently allows most Criteria methods to take no arguments, as well as nil arguments which are ignored. This means the following scope ends up with no conditions:

      irb(main):009:0> Band.in.all.gt.ne.and.not.lte
      => #<Mongoid::Criteria
        selector: {}
        options:  {}
        class:    Band
        embedded: false>
      

      ... and allows for the following interesting call which also ends up a no-op:

      irb(main):013:0> Band.ne(nil)
      => #<Mongoid::Criteria
        selector: {}
        options:  {}
        class:    Band
        embedded: false>
      

      This ticket proposes to:

      1. Require that most Criteria methods are provided arguments, such that Band.in raises an error.
      2. Require that all arguments are not nil, such that Band.in(nil) raises an error.

      Some operators will continue providing argument-free versions - Band.all and Band.not in particular since these are established use cases (first one is the classic no-op and the second one negates the following condition which wasn't provided yet). Band.all(nil) will become an error though.

            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: