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

unscoped doesn't work in embedded documents

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

      The default scope isn't removed from the selector of the returned Mongoid::Criteria instance.

      class Foo
        include Mongoid::Document
        embeds_many :bars
      end
      
      class Bar
        include Mongoid::Document
        embedded_in :foo
        field :flag, type: Boolean
        default_scope where(flag: true)
      end
      
      f.bars.create!(flag: true)
      f.bars.create!(flag: false)
      f.bars
      # => [#<Bar _id: 4e70a5f85c070f025c000003, _type: nil, flag: false>, #<Bar _id: 4e70a5fb5c070f025c000004, _type: nil, flag: true>]
      
      f.bars.all.selector
      # => {:flag=>true}   // ok
      f.bars.unscoped.selector
      # => {:flag=>true}   // wrong! should be {}
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            Pesa Davide Pesavento [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: