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

cascade_callbacks doesn't do before_destroy nor after_destroy

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

      class Parent
        include Mongoid::Document
      
        embeds_many :children, cascade_callbacks: true
      
        # uncommenting this is a work around to get the callbacks to fire
        # before_destroy :destroy_children
      
        # private
        # def destroy_children
        #   children.each(&:destroy)
        # end
      end
      
      class Child
        include Mongoid::Document
      
        before_destroy lambda { puts "before destroy" } # never fires
        after_destroy lambda { puts "after destroy" } # never fires
      end
      

      This used to be a bug for a long time in 2.x. So I always used that work around provided in the comments. Only recently did I take away the work around to rely on cascade_callbacks instead.

      Lo and behold when I now decided to move up to 3.x the bug was back

            Assignee:
            durran Durran Jordan
            Reporter:
            dbackeus David Backeus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: