I''ve got a bunch of tables that will act_as_tree. I don''t see a method (maybe I''m missing it) to "get myself and my children"? So I wanted to add it to my model, but I have so many acts_as_tree models I was trying to figure out a way to write my self_and_children method once, but I''m unfamiliar with extending the existing code in this way. Can somebody point me in the right direction? Thanks! (This code is for a rapid prototype, so scale and performance are not crucial issues, I''m just can''t bring myself to cut and paste the same method over and over again.) -- 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''ve just realized that if an object''s parent_id is set equal to itself, then it will include itself among it''s children. Perhaps that''s all I need, at least for my purposes right now. Sorry for the interruption. Duane Morin wrote:> I''ve got a bunch of tables that will act_as_tree. I don''t see a method > (maybe I''m missing it) to "get myself and my children"? So I wanted to > add it to my model, but I have so many acts_as_tree models I was trying > to figure out a way to write my self_and_children method once, but I''m > unfamiliar with extending the existing code in this way. Can somebody > point me in the right direction? Thanks! (This code is for a rapid > prototype, so scale and performance are not crucial issues, I''m just > can''t bring myself to cut and paste the same method over and over > again.)-- 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 -~----------~----~----~----~------~----~------~--~---
If you want the object and it''s children all in a 1D array: def self_and_children [self] + children end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---