By default, when you destroy a parent node all of the children nodes are destroyed as well. Is there a way I can modify this so that when you destroy a parent node all the children nodes are simply "moved up" within the tree? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
come to think of it, I should probably just create my own function called destroy_and_move_up or something =P On Nov 15, 1:04 pm, Stedwick <philip.broc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> By default, when you destroy a parent node all of the children nodes > are destroyed as well. > > Is there a way I can modify this so that when you destroy a parent > node all the children nodes are simply "moved up" within the tree? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Muller
2007-Nov-15 18:35 UTC
Re: acts_as_tree "soft destroy", ie. "move up" children
put it in the before_destroy callback of the model -- 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 -~----------~----~----~----~------~----~------~--~---
I tried that already. def before_destroy self.children.each {|child| child.parent_id = nil child.save } end (Yeah, I know, it doesn''t "move them up", it just sets them to new root nodes) However, rails won''t let me do that. It says I can''t modify a frozen hash. I''m not sure what that means, but I assume it means I can''t modify things that are about to be destroyed. On Nov 15, 1:35 pm, Thorsten Muller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> put it in the before_destroy callback of the model > -- > Posted viahttp://www.ruby-forum.com/90.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > put it in the before_destroy callback of the modelI tried using the before_destroy for a similar purpose - I wanted to stop deletion if the node has children. But I ran into trouble, the children were destroyed anyway. From what I have read elsewhere in this group, I believe the before_destroy is only called after dependent_destroy is actioned. That may be what is happening here. Seems to me to write a seperate method may be the way to go. Tonypm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---