I''m in progress of making a little folder system with Ruby on Rails. I''ve got a "folders" table. Each "folder" has got an id and a folder_id. The folder_id is supposed to represent the folders'' parent folder. How can I tell Rails? I would like Rails to automaticly delete all subfolders of a folder when I delete the folder it self. Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
David Trasbo wrote:> I''m in progress of making a little folder system with Ruby on Rails. > I''ve got a "folders" table. Each "folder" has got an id and a folder_id. > The folder_id is supposed to represent the folders'' parent folder. > > How can I tell Rails? > > I would like Rails to automaticly delete all subfolders of a folder when > I delete the folder it self. > > Any ideas?acts_as_tree ; see http://dev.rubyonrails.org/browser/plugins/acts_as_tree Stephan -- 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 -~----------~----~----~----~------~----~------~--~---
On 18 Apr 2008, at 09:48, David Trasbo wrote:> > I''m in progress of making a little folder system with Ruby on Rails. > I''ve got a "folders" table. Each "folder" has got an id and a > folder_id. > The folder_id is supposed to represent the folders'' parent folder. > > How can I tell Rails?As has been pointed out, acts_as_tree does this sort of thing. More generally you can do something like belongs_to :parent, :foreign_key => ''folder_id'', :class_name => ''Folder'' has_many :children :foreign_key => ''folder_id'', :class_name => ''Folder''> > > I would like Rails to automaticly delete all subfolders of a folder > when > I delete the folder it self.You can use the :dependent option to control that Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:>> How can I tell Rails?> As has been pointed out, acts_as_tree does this sort of thing. More > generally you can do something like > > belongs_to :parent, :foreign_key => ''folder_id'', :class_name => ''Folder'' > has_many :children :foreign_key => ''folder_id'', :class_name => ''Folder''Thank you, it works perfectly.>> I would like Rails to automaticly delete all subfolders of a folder >> when >> I delete the folder it self.> You can use the :dependent option to control thatOK, it works too. Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- Associated child records not created on creation of a parent.
- self-referencing has_many
- suggest for "ambiguous column" when JOIN associated tables
- acts_as_tree and traversing parent/child relationships
- Still Having Problems With :through When Going To Same Table... Help... please :-(