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

HATBM relationship count cannot be executed after an object is destroyed

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0.22
    • Component/s: None
    • Labels:

      Description

       ruby
      require "spec_helper"
       
      module Test_2812
        class Sandwich
          include Mongoid::Document
          has_and_belongs_to_many :meats
        end
       
        class Meat
          include Mongoid::Document
          has_and_belongs_to_many :sandwiches
        end
      end
       
      describe "2812" do
       
        it "issue" do
          # create a meats collection, without it, no error
          Test_2812::Meat.create!
       
          sandwich = Test_2812::Sandwich.create!
          sandwich.destroy
          sandwich.meats.count.should == 0
        end
       
      end
      

        1) 2812 issue
           Failure/Error: sandwich.meats.count.should == 0
           Moped::Errors::OperationFailure:
             The operation: #<Moped::Protocol::Command
               @length=124
               @request_id=8
               @response_to=0
               @op_code=2004
               @flags=[]
               @full_collection_name="mongoid_test.$cmd"
               @skip=0
               @limit=-1
               @selector={:count=>"test_2812_meats", :query=>{"$and"=>[{"_id"=>{"$in"=>nil}}]}}
               @fields=nil>
             failed with error 12580: "exception: invalid query"
             
             See https://github.com/mongodb/mongo/blob/master/docs/errors.md
             for details about this error.
           # ./lib/mongoid/contextual/mongo.rb:54:in `count'
           # ./lib/mongoid/contextual.rb:19:in `count'
           # ./lib/mongoid/relations/referenced/many.rb:10:in `count'
           # ./spec/dblock/2812_spec.rb:23:in `block (2 levels) in <top (required)>'
      
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: