Peter Jagielski
2006-Feb-15 18:22 UTC
[Rails] Need help setting up and iterating thru a tree
Guys,
Newbie here. Given the following table named Employee_Links:
ID Emp_ID Parent_ID
-- ------ ---------
1 200 100
2 300 100
3 300 200
4 400 100
5 500 400
6 500 300
I''d like to be able to generate a tree that looks like this:
100
|-200
|-300
|-500
|-300
|-400
|-500
Note that where 500''s Parent_ID = 300 (row 6), 500 is linked to the
first 300 it finds in the tree diagram.
After some experimentation, it appears that ACTS_AS_TREE won''t work
since I have nodes that will have >1 parent node. Is there a simple way
to setup the relationship (HABTM?) AND the code that generates the tree
diagram? I''ve looked at various similar examples online, and I have
the
new Rails Recipes PDF book, but I haven''t been able to figure this one
out without writing a lot of code, which I have a feeling is the wrong
approach.
Help!
--
Posted via http://www.ruby-forum.com/.
