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.
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???
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.
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?
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)