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

default_scope order overwrites other scope conditions

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

      ENV["RAILS_ENV"] ||= "development"
      require "./config/environment"
      
      class Comment
        include Mongoid::Document
      
        default_scope asc(:_id)
        scope :pre, where(:video_timestamp => nil)
        scope :timestamped, where(:video_timestamp.ne => nil)
      
      end
      
      p Comment.pre.selector # => {}
      p Comment.unscoped.pre.selector # => {}
      p Comment.where(:video_timestamp => nil).selector # => {"video_timestamp"=>nil}
      p Comment.timestamped.selector # => {"video_timestamp"=>{"$ne"=>nil}}
      

      It works correctly when defining some other condition in default_scope.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kbackowski kbackowski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: