Category and subcategories in database


#1

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


#2

ActiveRecord is great for this kind of model.

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

Brandon


#3

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/characters/db/tables.sql

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

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

Peter