# Has\_many :through problem

**URL:** <https://www.ruby-forum.com/t/has-many-through-problem/119405>\
**Category:** Rails\
**Created:** [November 6, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/has-many-through-problem/119405 "2007-11-06T19:39:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![colemanm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@colemanm](https://www.ruby-forum.com/u/colemanm)\
**Post date:** [November 6, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/has-many-through-problem/119405/1 "2007-11-06T19:39:43Z")

</div>

(sorry for the double post, somehow I accidentally prematurely posted  
part of this…)

I’m building a simple support ticket system for use in our office. I’ve  
got a model called Ticket and one called Category and I’m trying to set  
it up so that I can add categories at will and assign many categories to  
a single ticket.

I’m trying to use the has\_many :through association to accomplish this,  
but I’ve run into an issue.

Here’s the basic setup:

class Ticket \< ActiveRecord::Base  
has\_many :categoryassociations  
has\_many :categories, :through =\> :categoryassociations  
end

class CategoryAssociation \< ActiveRecord::Base  
belongs\_to :ticket  
end

class Category \< ActiveRecord::Base  
has\_many :categoryassociations  
has\_many :tickets, :through =\> :categoryassociations  
end

I’m now receiving an error “uninitialized constant  
Ticket::Categoryassociation.”

I should be able to use @ticket.categories in the view to spit out the  
associated categories, correct? Does this all look like it should work?

---

<div class="post-metadata">

**Author:** ![colemanm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@colemanm](https://www.ruby-forum.com/u/colemanm)\
**Post date:** [November 6, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/has-many-through-problem/119405/2 "2007-11-06T19:45:20Z")

</div>

On 6 Nov 2007, at 18:39, Coleman Mccormick wrote:

> a single ticket.  
> end  
> if you say :categoryassociations, rails assumes your model is  
> Categoryassociation. You need :category\_associations for it to look  
> for CategoryAssociation
> 
> class CategoryAssociation \< ActiveRecord::Base  
> belongs\_to :ticket  
> end

this is missing a belongs\_to :category.

Fred
