Folks, I''m trying to figure out the best approach to creating a linked list conceptually in RoR. This is what I''m looking at doing and want to know if there is a best practice approach to this already (my search didn''t seem to indicate this) OR if I''m completely off base on the naming convention I''m using: category table id name categories_categories table (not defined as a model; should it be?) id category_id parent_category_id Then I should be able to do things like this... Fruit -> Berry -> Blueberry Fruit -> Berry -> Raspberry Fruit -> Apple -> Rome Food -> Fruit Food -> Beverage etc. where I create these by recursively(?) accessing the categories_categories data joined to the category data. The start of a category will be implied where parent_category_id is 0. And those parent records could be a foreign key like so categories_categories_object table object_id categories_categories_id where object is the other model/table in the many-to-many relationship. Is this the appropriate way to do something like this? If not, could someone point me to some documentation or an example of how I should be handling this. Thanks, Jack --~--~---------~--~----~------------~-------~--~----~ 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 just found some info in the Agile Rails book and with a bit more searching I discovered I could look into one of these: acts_as_list acts_as_tree acts_as_nested I don''t think the list feature works since I''m looking at a hierarchy and want to be able to re-use the same term in different levels. Can acts_as_tree allow for multiple trees? i.e. more than one NULL parent_id? This also seems to imply that I do want to make my categories_categories table a full blown model, with a better name of course. Could someone confirm I''m on the right track? Thanks, Jack On Apr 1, 2:03 pm, Jack <jl...-4Ng6DfrEGID2fBVCVOL8/A@public.gmane.org> wrote:> Folks, > > I''m trying to figure out the best approach to creating a linked list > conceptually in RoR. This is what I''m looking at doing and want to > know if there is a best practice approach to this already (my search > didn''t seem to indicate this) OR if I''m completely off base on the > naming convention I''m using: > > category table > id > name > > categories_categories table (not defined as a model; should it be?) > id > category_id > parent_category_id > > Then I should be able to do things like this... > > Fruit -> Berry -> Blueberry > Fruit -> Berry -> Raspberry > Fruit -> Apple -> Rome > Food -> Fruit > Food -> Beverage > etc. > > where I create these by recursively(?) accessing the > categories_categories data joined to the category data. The start of a > category will be implied where parent_category_id is 0. And those > parent records could be a foreign key like so > > categories_categories_object table > object_id > categories_categories_id > > where object is the other model/table in the many-to-many > relationship. > Is this the appropriate way to do something like this? If not, could > someone point me to some documentation or an example of how I should > be handling this. > > Thanks, > Jack--~--~---------~--~----~------------~-------~--~----~ 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 Wed, Apr 1, 2009 at 1:03 PM, Jack <jlk4p-4Ng6DfrEGID2fBVCVOL8/A@public.gmane.org> wrote:> I''m trying to figure out the best approach to creating a linked list > conceptually in RoR.http://www.koders.com/ruby/fidCB5A463AB556F4FFD20E03139FF59563B118D108.aspx?s=socket -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Jack wrote:> Folks, > > I''m trying to figure out the best approach to creating a linked list > conceptually in RoR.[...] What you describe is a tree, not really a linked list. You could use acts_as_tree for this, but you''ll probably get better results with awesome_nested_set or something similar. Best, -- Marnen Laibow-Koser marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org http://www.marnen.org -- 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 -~----------~----~----~----~------~----~------~--~---