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

Opinionated short-circuiting of specific query shapes

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • 9.1.0
    • Affects Version/s: None
    • Component/s: Query
    • None

      Rails 6.1 introduced the following behavior in ActiveRecord:

      Avoid making query when using `where(attr: [])`
      https://github.com/rails/rails/pull/37266

      Mongoid should implement something similar. For example, the following queries are guaranteed never to return any results:

      Users.any_in(name: [])
      Users.where(name: 'Bob').where(name: 'Joe')

      Such code should return a Mongoid::Criteria but calling .to_a on that criteria returns [] without generating a DB query.

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: