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

Nested Attributes _destroy does not respect Paranoia

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 2.4.0
    • Component/s: None
    • Labels:

      Description

      class Parent
        include Mongoid::Document
       
        accepts_nested_attributes_for :childs, :allow_destroy => true
        embeds_many :childs, :cascade_callbacks => true
      end
       
      class Child
        include Mongoid::Document
        include Mongoid::Paranoia
       
        embedded_in :parent
      end
      

      ruby-1.9.2-p290 :046 > p = Parent.create
       => <Parent _id: 4eea357c8035444720000010, _type: nil> 
      ruby-1.9.2-p290 :047 > c1 = p.childs.create
       => <Child _id: 4eea357f8035444720000011, _type: nil, deleted_at: nil> 
      ruby-1.9.2-p290 :048 > c2 = p.childs.create
       => <Child _id: 4eea35818035444720000012, _type: nil, deleted_at: nil> 
      ruby-1.9.2-p290 :049 > p.childs_attributes = {"0" => {"_id" => c1.id}, "1" => {"_id"=>c2.id, "_destroy" => true}}
       => {"0"=>{"_id"=>BSON::ObjectId('4eea357f8035444720000011')}, "1"=>{"_id"=>BSON::ObjectId('4eea35818035444720000012'), "_destroy"=>true}} 
      ruby-1.9.2-p290 :050 > p.save  # this shouldn't delete the child, it should just set the deleted_at
       => true 
      ruby-1.9.2-p290 :051 > p.childs
       => [<Child _id: 4eea357f8035444720000011, _type: nil, deleted_at: nil, hi: nil>] 
      ruby-1.9.2-p290 :055 > p.childs.unscoped.to_a
       => [<Child _id: 4eea357f8035444720000011, _type: nil, deleted_at: nil, hi: nil>]
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nader Nader Akhnoukh
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: