Destroying embedded doc via nested attributes _destroy should not raise DocumentNotFound

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Docs
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently, the following code raises Mongoid::Errors::DocumentNotFound

      class Person
        include Mongoid::Document
      
        embeds_many :phones
      
        accepts_nested_attributes_for :phones
      end
      
      class Phone
        include Mongoid::Document
      
        embedded_in :person
      end
      
      person = Person.create!
      person.update_attributes!(phones_attributes: [{ id: 'a' * 24, _destroy: true }])
      #=> raises Mongoid::Errors::DocumentNotFound

      It looks like this happens because the code first tries to "find" the embedded object (which raises error) before attempting to delete it.

      In this case, it would be much better to just ignore the non-existent embedded object, because it was probably already deleted. This seems to happen a lot in parts of the app where many users might be trying to modify the same object.

              Assignee:
              Jamis Buck
              Reporter:
              Johnny Shields
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: