Forum: Ruby on Rails Associations in the same table

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.
snacktime (Guest)
on 2007-07-27 07:20
(Received via mailing list)
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
JN_Coward (Guest)
on 2007-07-27 07:41
(Received via mailing list)
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
snacktime (Guest)
on 2007-07-27 07:58
(Received via mailing list)
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
This topic is locked and can not be replied to.