Forum: Ruby on Rails Need help setting up and iterating thru a tree

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6cf3e18ebc948992a4cbe83330496e36?d=identicon&s=25 Peter Jagielski (sweetpete)
on 2006-02-15 19:22
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!
This topic is locked and can not be replied to.