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

cascade! is never called for paranoid documents

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.1
    • 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.

            Assignee:
            durran Durran Jordan
            Reporter:
            voke Gustav
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: