Nested attributes raise UnknownAttribute when _destroy: true is sent with a foreign child _id

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.1.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Mongoid::Association::Nested::Many#update_nested_relation raises Mongoid::Errors::UnknownAttribute when nested attributes include _destroy: true for a child whose _id is not already in the parent's relation (e.g. a new parent receiving an existing child's _id).

      The if branch strips _destroy via destroyable? before calling update_document. The else branch calls update_document first, so _destroy is still in the attrs hash when assign_attributes is invoked — and any model without a _destroy field (and without Mongoid::Attributes::Dynamic) blows up.

      Expected

      The _destroy directive is honored or silently no-ops. No exception for a documented nested-attributes key.

      Actual

      Mongoid::Errors::UnknownAttribute: Attempted to set a value for '_destroy' which is not allowed on the model Child.

        1. bug.rb
          0.7 kB
          Kieran Pilkington (EXT)

            Assignee:
            Jamis Buck
            Reporter:
            Kieran Pilkington (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: