Associations in the same table


#1

I’m trying to figure out what is the ‘rails’ way of doing this. I’m
expressing products and their variations. Variations are just
products that belong to a parent product. It’s basically a tree
structure. Variations can also belong to other variations. What I’m
trying to decide is the best way to get all the descendents for a
product in one query and keep the table as normalized as possible.
The un-normalized way would be to add a root_id column, or I could use
a join table I guess. Any thoughts?

Chris


#2

Check out acts_as_nested_set, haven’t used it myself, but apparently
it’s really nice for this sort of stuff, allowing you to get
everything in one query.

/Jonas


#3

On 7/26/07, JN_Coward removed_email_address@domain.invalid wrote:

Check out acts_as_nested_set, haven’t used it myself, but apparently
it’s really nice for this sort of stuff, allowing you to get
everything in one query.

I saw that. I was a little concerned about the added complexity of
removing or moving sets to different locations in the tree. I should
play with it a little though to see how well it works in practice.

Chris