-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Environment
ruby 1.9.2-p180
mongoid 2.0.0
Example
require "rubygems"
require "mongoid"
require 'rspec'
Mongoid.database = Mongo::Connection.new().db('testdb')
Mongoid::logger = Logger.new(STDOUT)
class Sky
include Mongoid::Document
include Mongoid::Paranoia
references_many :clouds, :dependent => :destroy
end
class Cloud
include Mongoid::Document
referenced_in :sky
end
sky = Sky.create!
cloud = Cloud.create!(:sky => sky)
sky.destroy
Sky.count.should == 0
Cloud.count.should == 0 # => expected: 0 got: 1 (using ==)
Conclusion
:dependent => :destroy has no effect since the remove() method is overwritten by the paranoia module and the cascade! method is therefore never called.
I'm not sure how it's supposed to work but neither destroy nor destroy! calls the cascade! method but both triggers the :destroy callbacks.