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

bug with multi-key where() on embedded paranoia docs?

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

      Maybe I'm just nuts or fundamentally don't understand some part of this, but this seems like a bug to me:

      GIVEN:

      class User
        include Mongoid::Document
        
        embeds_many :pets
        
      end
      
      class Pet
        include Mongoid::Document
        include Mongoid::Paranoia
      
        embedded_in :user
      
        field :species
        
      end
      
      

      IN CONSOLE:

      ruby-1.9.3-p125 :019 > User.count
       => 1
      
      ruby-1.9.3-p125 :020 > User.first.pets
       => [
         #<Pet _id: 4fabed13d5c23c168b000001, _type: nil, deleted_at: 2012-05-10 16:30:41 UTC, species: "dog">, 
         #<Pet _id: 4fabed24d5c23c168b000002, _type: nil, deleted_at: nil, species: "dog">
         ] 
      
      ruby-1.9.3-p125 :021 > User.where('pets.species' => 'dog').count
       => 1
      
      ruby-1.9.3-p125 :022 > User.where('pets.species' => 'dog', 'pets.deleted_at' => nil).count
       => 0 
      

      WHOA! WHAT!? Shouldn't that last query return 1 ? We have a User that has at least 1 active (i.e. not paranoia-deleted) dog. Just because one of his dogs has been deleted doesn't mean we should now ignore the other, not-deleted dog...

      I'm fully aware this may be a basic mongo query thing that I'm missing. But this just doesn't seem like the expected behavior, at least to me. Would be very happy for someone to explain what I'm missing here...

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

              Created:
              Updated:
              Resolved: