Topic: Question about :dependent => :delete_all on nested has_many associatio
Alright, I have three models as follows:
class Section < ActiveRecord::Base
has_many :volumes, :dependent => :delete_all
class Volume < ActiveRecord::Base
has_many :chapters, :dependent => :delete_all
class Chapter < ActiveRecord::Base
I'd like for everything to cascading delete when I delete a section, however, if I have :dependent set to :delete_all, only the volumes associated with it will be destroyed and I will be left with orphaned chapter records. I have experimented with some things and if I set :dependent to :destroy for the Section model then everything gets destroyed properly except I have an extremely heavy before_destroy that I do not want to run.
Is there anyway I can have it work with :delete_all? or is there a way to check if I'm deleting all in my before_destroy so I can skip my clean up (that way I can just use :destroy on the Volume model)?
Thanks for the help.