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.
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???
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, [email protected] [email protected] wrote:
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 B.
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.
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 [email protected] wrote:
On Dec 6, 10:37 am, “Ryan B.” [email protected] wrote:
have several children - and children could have more children, etc.
Ryan B.
–
Ryan B.
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 [email protected] wrote:
a
I feel that going with a forums + topics + posts database schema is
more
–
Ryan B.
–
Ryan B.
–
Ryan B.
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,
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.
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…