mscaldas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 20:19 UTC
Question about acts_as_tree
Hi All, I was wondering if a Class declared with acts_as_tree can have more than one root, i.e., parent_id = null? this will basically support multiple trees within the same table. My implementation idea is to have a lookups table where the records that have parent_id are the lookup Types and each one of those will have several children - and children could have more children, etc. I know I can achieve the same thing for creating a dummy root and make the first level my "types", but I thought the idea above is cleaner in my opinion. thanks, Marcelo. --~--~---------~--~----~------------~-------~--~----~ 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 been tackling acts_as_tree in trying to write forum software. The original posts are each a root, with the replies as children. So, yes, you can have as many roots as you want. The challenge I am faced with is how to traverse a full tree to get the last post???? On Dec 6, 4:19 am, "mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > I was wondering if a Class declared with acts_as_tree can have more > than one root, i.e., parent_id = null? > > this will basically support multiple trees within the same table. > > My implementation idea is to have a lookups table where the records > that have parent_id are the lookup Types and each one of those will > have several children - and children could have more children, etc. > > I know I can achieve the same thing for creating a dummy root and make > the first level my "types", but I thought the idea above is cleaner in > my opinion. > > thanks, > > Marcelo.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Types... you mean like "topics", right? I feel that going with a forums + topics + posts database schema is a much better idea than acts_as_tree, but that''s just me. On Dec 6, 2007 6:49 AM, mscaldas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mscaldas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi All, > > I was wondering if a Class declared with acts_as_tree can have more > than one root, i.e., parent_id = null? > > this will basically support multiple trees within the same table. > > My implementation idea is to have a lookups table where the records > that have parent_id are the lookup Types and each one of those will > have several children - and children could have more children, etc. > > I know I can achieve the same thing for creating a dummy root and make > the first level my "types", but I thought the idea above is cleaner in > my opinion. > > thanks, > > Marcelo. > > >-- Ryan Bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan--Can you explain the "I feel that going with a forums + topics + posts database schema is a much better idea than acts_as_tree" a little more? Are you suggesting that ''topic'' be segregated into it''s own table? Now I have now a forums + (posts w/topics) schema. On Dec 6, 10:37 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Types... you mean like "topics", right? > > I feel that going with a forums + topics + posts database schema is a much > better idea than acts_as_tree, but that''s just me. > > On Dec 6, 2007 6:49 AM, mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi All, > > > I was wondering if a Class declared with acts_as_tree can have more > > than one root, i.e., parent_id = null? > > > this will basically support multiple trees within the same table. > > > My implementation idea is to have a lookups table where the records > > that have parent_id are the lookup Types and each one of those will > > have several children - and children could have more children, etc. > > > I know I can achieve the same thing for creating a dummy root and make > > the first level my "types", but I thought the idea above is cleaner in > > my opinion. > > > thanks, > > > Marcelo. > > -- > Ryan Bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Are you suggesting that ''topic'' be segregated into it''s own table? Now Ihave now a forums + (posts w/topics) schema. Indeed I am suggesting this. A forum has many topics, topics have many posts and then posts belong to topics. I find it easier to delete all posts from a topic this way (instead of iterating through all the posts and then deleting all of their children, it''s basically a DELETE FROM `posts` WHERE `topic_id` = ''topic.id''). I also allow for topics to have their own subjects. I''ve never found a use for a tree view in a forum system. If anyone has anything to say about another post I find that they [quote] the relevant sections of the first post and then reply to it. On Dec 6, 2007 1:14 PM, yachtman <carson.cole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ryan--Can you explain the "I feel that going with a forums + topics + > posts database schema is a much better idea than acts_as_tree" a > little more? > > Are you suggesting that ''topic'' be segregated into it''s own table? Now > I have now a forums + (posts w/topics) schema. > > > > On Dec 6, 10:37 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Types... you mean like "topics", right? > > > > I feel that going with a forums + topics + posts database schema is a > much > > better idea than acts_as_tree, but that''s just me. > > > > On Dec 6, 2007 6:49 AM, mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Hi All, > > > > > I was wondering if a Class declared with acts_as_tree can have more > > > than one root, i.e., parent_id = null? > > > > > this will basically support multiple trees within the same table. > > > > > My implementation idea is to have a lookups table where the records > > > that have parent_id are the lookup Types and each one of those will > > > have several children - and children could have more children, etc. > > > > > I know I can achieve the same thing for creating a dummy root and make > > > the first level my "types", but I thought the idea above is cleaner in > > > my opinion. > > > > > thanks, > > > > > Marcelo. > > > > -- > > Ryan Bigg > > >-- Ryan Bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan, Thanks for the help. I''ve been designing schemas for years and I don''t know why that layout didn''t occur to me. Yikes. It''s so darn simple. I''ve already got it implemented and it works great. On Dec 6, 11:10 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Are you suggesting that ''topic'' be segregated into it''s own table? Now I > > have now a forums + (posts w/topics) schema. > > Indeed I am suggesting this. > > A forum has many topics, topics have many posts and then posts belong to > topics. I find it easier to delete all posts from a topic this way (instead > of iterating through all the posts and then deleting all of their children, > it''s basically a DELETE FROM `posts` WHERE `topic_id` = ''topic.id''). I also > allow for topics to have their own subjects. I''ve never found a use for a > tree view in a forum system. If anyone has anything to say about another > post I find that they [quote] the relevant sections of the first post and > then reply to it. > > On Dec 6, 2007 1:14 PM, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Ryan--Can you explain the "I feel that going with a forums + topics + > > posts database schema is a much better idea than acts_as_tree" a > > little more? > > > Are you suggesting that ''topic'' be segregated into it''s own table? Now > > I have now a forums + (posts w/topics) schema. > > > On Dec 6, 10:37 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Types... you mean like "topics", right? > > > > I feel that going with a forums + topics + posts database schema is a > > much > > > better idea than acts_as_tree, but that''s just me. > > > > On Dec 6, 2007 6:49 AM, mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > > > > I was wondering if a Class declared with acts_as_tree can have more > > > > than one root, i.e., parent_id = null? > > > > > this will basically support multiple trees within the same table. > > > > > My implementation idea is to have a lookups table where the records > > > > that have parent_id are the lookup Types and each one of those will > > > > have several children - and children could have more children, etc. > > > > > I know I can achieve the same thing for creating a dummy root and make > > > > the first level my "types", but I thought the idea above is cleaner in > > > > my opinion. > > > > > thanks, > > > > > Marcelo. > > > > -- > > > Ryan Bigg > > -- > Ryan Bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
For some reason when I posted the message before yours I had a feeling like it was going to get shot down in flames (for a reason that still evades me, I guess the Internet''s conditioned me). Instead, it got praised. Thanks :) I was "inspired" by vBulletin and phpbb. On Dec 6, 2007 1:58 PM, yachtman <carson.cole-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ryan, Thanks for the help. I''ve been designing schemas for years and I > don''t know why that layout didn''t occur to me. Yikes. It''s so darn > simple. I''ve already got it implemented and it works great. > > On Dec 6, 11:10 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Are you suggesting that ''topic'' be segregated into it''s own table? Now > I > > > > have now a forums + (posts w/topics) schema. > > > > Indeed I am suggesting this. > > > > A forum has many topics, topics have many posts and then posts belong to > > topics. I find it easier to delete all posts from a topic this way > (instead > > of iterating through all the posts and then deleting all of their > children, > > it''s basically a DELETE FROM `posts` WHERE `topic_id` = ''topic.id''). I > also > > allow for topics to have their own subjects. I''ve never found a use for > a > > tree view in a forum system. If anyone has anything to say about another > > post I find that they [quote] the relevant sections of the first post > and > > then reply to it. > > > > On Dec 6, 2007 1:14 PM, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > Ryan--Can you explain the "I feel that going with a forums + topics + > > > posts database schema is a much better idea than acts_as_tree" a > > > little more? > > > > > Are you suggesting that ''topic'' be segregated into it''s own table? Now > > > I have now a forums + (posts w/topics) schema. > > > > > On Dec 6, 10:37 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Types... you mean like "topics", right? > > > > > > I feel that going with a forums + topics + posts database schema is > a > > > much > > > > better idea than acts_as_tree, but that''s just me. > > > > > > On Dec 6, 2007 6:49 AM, mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > Hi All, > > > > > > > I was wondering if a Class declared with acts_as_tree can have > more > > > > > than one root, i.e., parent_id = null? > > > > > > > this will basically support multiple trees within the same table. > > > > > > > My implementation idea is to have a lookups table where the > records > > > > > that have parent_id are the lookup Types and each one of those > will > > > > > have several children - and children could have more children, > etc. > > > > > > > I know I can achieve the same thing for creating a dummy root and > make > > > > > the first level my "types", but I thought the idea above is > cleaner in > > > > > my opinion. > > > > > > > thanks, > > > > > > > Marcelo. > > > > > > -- > > > > Ryan Bigg > > > > -- > > Ryan Bigg > > >-- Ryan Bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
mscaldas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-06 14:22 UTC
Re: Question about acts_as_tree
Oh great, So quick question: (maybe two!) 1 - What happens when you call the root() method? 2 - how do you get a specific root()? 3 - How do you get all the roots? thanks, On Dec 5, 9:34 pm, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve been tacklingacts_as_treein trying to write forum software. The > original posts are each aroot, with the replies as children. So, yes, > you can have as many roots as you want. > > The challenge I am faced with is how to traverse a full tree to get > the last post???? > > On Dec 6, 4:19 am, "mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi All, > > > I was wondering if a Class declared withacts_as_treecan have more > > than oneroot, i.e., parent_id = null? > > > this will basically supportmultipletrees within the same table. > > > My implementation idea is to have a lookups table where the records > > that have parent_id are the lookup Types and each one of those will > > have several children - and children could have more children, etc. > > > I know I can achieve the same thing for creating a dummyrootand make > > the first level my "types", but I thought the idea above is cleaner in > > my opinion. > > > thanks, > > > Marcelo.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
To get all of the roots..parent_id will be null (this is a requirement of acts_as_tree) parent_posts = Post.find(:all, :conditions => "parent_id is NULL" A specific root, you''ll need the id.. post = Post.find_by_id(id) Not sure what calling the root method means... On Dec 6, 10:22 pm, "mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh great, > > So quick question: (maybe two!) > 1 - What happens when you call the root() method? > 2 - how do you get a specific root()? > 3 - How do you get all the roots? > > thanks, > > On Dec 5, 9:34 pm, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve been tacklingacts_as_treein trying to write forum software. The > > original posts are each aroot, with the replies as children. So, yes, > > you can have as many roots as you want. > > > The challenge I am faced with is how to traverse a full tree to get > > the last post???? > > > On Dec 6, 4:19 am, "mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <mscal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > > I was wondering if a Class declared withacts_as_treecan have more > > > than oneroot, i.e., parent_id = null? > > > > this will basically supportmultipletrees within the same table. > > > > My implementation idea is to have a lookups table where the records > > > that have parent_id are the lookup Types and each one of those will > > > have several children - and children could have more children, etc. > > > > I know I can achieve the same thing for creating a dummyrootand make > > > the first level my "types", but I thought the idea above is cleaner in > > > my opinion. > > > > thanks, > > > > Marcelo.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---