Forum: Ruby on Rails Category and subcategories in database

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.
B4c21866846b5dc55c68acd66c4c2f11?d=identicon&s=25 Mike Mannakee (Guest)
on 2006-05-07 05:56
(Received via mailing list)
I have a project I'm trying to decide if I want to use rails for.  I'm
new
to rails, so I'm not sure how easy it would be to implement something
like
this using ActiveRecord.  Here's the situation:

Category > subcategory > subcategory > product
Category > subcategory > product

Some categories will have many subcategories, others few.  I want to use
adjacency lists in the database like

ID    CATEGORY    PARENT

where top-level categories simply have no parent, but subcategories do.
My
concern is whether Rails, using ActiveRecord, can be made to understand
this.  I'm coming from PHP and know I can code it there.  The question
is
can I do this same thing in Rails, and what will it involve?  Does
anyone
have any experience that will help?

Mike
4f553f0a2d333e688d639fbf6d2d889a?d=identicon&s=25 Brandon Keepers (Guest)
on 2006-05-07 06:02
(Received via mailing list)
ActiveRecord is great for this kind of model.

http://api.rubyonrails.org/classes/ActiveRecord/Acts/Tree/
ClassMethods.html

Brandon
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-05-07 06:05
(Received via mailing list)
Hi Mike,

ActiveRecord can do all that you want. I have implemented exactly this
system in the store.rb schema.

Project
http://trac.vaillant.ca/store.rb/

Schema
http://trac.vaillant.ca/store.rb/browser/branches/...

demo store
http://characters.michaux.ca/

Hopefully these links can jumpstart you. That is part of the reason
for the project.

Peter
This topic is locked and can not be replied to.