mongoid/mongoid — Issue #1502: Nested Attributes _destroy does not respect Paranoia
Author: iamnader
Created: 2011-12-15 18:06:27+00:00
State: open

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
=> #
ruby-1.9.2-p290 :047 > c1 = p.childs.create
=> #
ruby-1.9.2-p290 :048 > c2 = p.childs.create
=> #
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
=> [#]
ruby-1.9.2-p290 :055 > p.childs.unscoped.to_a
=> [#]