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

HABTM assignment to empty array broken

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

      
      require "spec_helper"
      
      class Exhibitor
        include Mongoid::Document
        has_and_belongs_to_many :artworks
      end
      
      class Artwork
        include Mongoid::Document
        has_and_belongs_to_many :exhibitors
      end
            
      describe "Test" do
      
        before do
          [ Exhibitor, Artwork ].each(&:delete_all)
        end
        
        describe "works" do
        
          it "sometimes" do
            exhibitor = Exhibitor.create!
            artwork = Artwork.create!
            exhibitor.artworks = [ artwork ]
            exhibitor.save!
            exhibitor.artworks.count.should == 1
            
            exhibitor = Exhibitor.find(exhibitor.id)
            exhibitor.artworks.count.should == 1
            exhibitor.artworks = [] # assigning to nil here works, maybe acceptable workaround for now
            exhibitor.save!
            Exhibitor.find(exhibitor.id).artworks.count.should == 0 # returns 1
          end
          
        end
        
      end
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: