Hi there, what is the "Rails way" to delete a record in a model "tree" structure like the following one ? User ===has_many :projects Project ======has_many :tasks Task ===has_many :sub_tasks Sub_task =======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! Tom -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Franz Strebel
2008-Apr-11 14:09 UTC
Re: Deleting a db record in a "tree-like" model structure
has_many :children, :dependent => :destroy On Fri, Apr 11, 2008 at 4:07 PM, Tom Ha <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi there, > > what is the "Rails way" to delete a record in a model "tree" structure > like the following one ? > > User > ===> has_many :projects > > Project > ======> has_many :tasks > > Task > ===> has_many :sub_tasks > > Sub_task > =======> 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! > Tom > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damn, I love it!! Thanks a lot, Franz! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---