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

delete_all conditions don't work with aliased fields.

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

      It would seem that delete_all doesn't map aliased fields in its conditions param correctly. It does the right thing when combined with a separate where call. destroy_all does not seem to have this issue:

      class Foo
        include Mongoid::Document
      
        field :_id, :as => :uid, :type => String
      end
      
      Foo.create(:uid => "a")
      Foo.create(:uid => "b")
      Foo.create(:uid => "c")
      Foo.create(:uid => "d")
      
      Foo.delete_all(:uid => "a") # => 0
      Foo.destroy_all(:uid => "b") # => 1
      Foo.where(:uid => "c").delete_all # => 1
      Foo.where(:uid => "d").destroy_all # => 1
      
      Foo.all.map(&:uid) # => ["a"]
      

      From the docs I'd expect delete_all and destroy_all to behave in the same way when selecting documents to operate on.

      Versions:
      mongoid: 4.0.0
      moped: 2.0.1
      origin: 2.1.1

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            alext Alex Trepca
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: