# Multiple categories for a product

**URL:** <https://www.ruby-forum.com/t/multiple-categories-for-a-product/120761>\
**Category:** Rails\
**Created:** [November 20, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/multiple-categories-for-a-product/120761 "2007-11-20T13:00:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [November 20, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/multiple-categories-for-a-product/120761/1 "2007-11-20T13:00:10Z")

</div>

I’m currently using acts\_as\_tree to handle my categories hierarchy.

Animals  
Birds  
Dogs  
Themes  
Farm  
City

My product model currently just has a “product\_id” column, with an  
acts\_as\_tree object and belongs\_to :category

If I wanted to define a product that belonged to more than one category  
(ie  
“Rooster” – could belong to both Bird and Farm categories  
simultaneously),  
what is the best way to do this?

–  
Anthony E.  
Ph: 408-656-2473  
var (bonita, farley) = new Dog;  
farley.barks(“very loud”);  
bonita.barks(“at strangers”);

[http://chovy.dyndns.org/resume/](http://chovy.dyndns.org/resume/)  
[http://utuxia.com/consulting](http://utuxia.com/consulting)

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [November 20, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/multiple-categories-for-a-product/120761/2 "2007-11-20T16:12:54Z")

</div>

Then you need a new model to have a relationship through 🙂

_something like this_  
category \<=\> categories\_products \<=\> products

and then categories\_products should continue only (category\_id and  
product\_id)
