Deleting a db record in a "tree-like" model structure

Hi there,

what is the “Rails way” to delete a record in a model “tree” structure
like the following one ?


has_many :projects


has_many :tasks


has_many :sub_tasks


has_many :sub_sub_tasks (etc…)

-> I don’t know how to delete from my db a project record AND at the
same time delete all its dependent

  • tasks,
  • sub_tasks,
  • sub_sub_tasks, etc. with it (so that NO child record can survive in
    the db WITHOUT a parent record).

Who can help me out?!

Thank you very much for your help on this!

has_many :children, :dependent => :destroy

On Fri, Apr 11, 2008 at 4:07 PM, Tom Ha

Damn, I love it!!

Thanks a lot, Franz!