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

Callbacks: parent_id is nil when child is destroyed via nested attributes

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

      Very similar to MONGOID-2127 except it also happens with referenced relations.

      class Page
        has_many :components
        accepts_nested_attributes_for :components, :allow_destroy => true
      end
      
      class Component
        belongs_to :page
        after_save :touch_page
        
        def touch_page
          page.touch
        end
      end
      

      When a nested component is given field _destroy = 1 and the page object is saved, the component callback is fired but returns undefined method 'touch' for nil:NilClass. It seems like page_id is getting wiped too soon. Same for after_destroy too. Is this normal?

      mongoid (3.0.5)
      rails (3.2.2)

            Assignee:
            Unassigned Unassigned
            Reporter:
            russellbrown russellbrown
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: