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

Destroying an embedded model referenced multiple times nullifies only one reference

      Related to https://jira.mongodb.org/browse/MONGOID-4734?filter=26864:

      class Address
      
        include Mongoid::Document
      
        field :city, type: String
        
        embedded_in :addressable, polymorphic: true
      
      end
      
       
      
      class Company
      
        include Mongoid::Document
      
         embeds_one :address, class_name: 'Address', as: :addressable
      
        embeds_one :delivery_address, class_name: 'Address', as: :addressable
      
      end
      
      address = Address.new
      company = Company.create!(delivery_address: address, address: address)
      address.destroy
      
      company.reload
      

      Both addresses should be nil, however only delivery_address is nullified.

      This issue may be invalid because the address is only capable of referencing the company once, thus whether it is fixable depends on whether we traverse associations from embedded document to host document or from host one to embedded one.

            Assignee:
            Unassigned Unassigned
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: