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

Scopes ignore procs that return none criteria

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I have a scope that is supposed to conditionally return the none criteria. I noticed that when the none criteria is returned by a lambda (or regular proc via Proc.new), everything in the colllection is returned instead. The scope seems to be completely ignoring the none criteria. I tested this behavior further by making simple named scopes that simply return none and those are also ignored.

      An example:

      class Simple
        include Mongoid::Document
      
        field :name, type: String
      
        scope :nothing, -> { none }
      end
      

      This simple model's nothing scope would return everything in the collection, rather than not hitting the database at all. Outside of scopes, none seems to work as intended. I have also noted that this behavior transfers to {{default_scope}}s as well.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            Valdez42 Valdez42 [X]
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: