# Namespaced models with has\_many :through

**URL:** <https://www.ruby-forum.com/t/namespaced-models-with-has-many-through/186495>\
**Category:** Rails\
**Created:** [April 8, 2010, 12:00am UTC](https://www.ruby-forum.com/t/namespaced-models-with-has-many-through/186495 "2010-04-08T00:00:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zettabyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b19c9b/32.png) [@zettabyte](https://www.ruby-forum.com/u/zettabyte)\
**Post date:** [April 8, 2010, 12:00am UTC](https://www.ruby-forum.com/t/namespaced-models-with-has-many-through/186495/1 "2010-04-08T00:00:46Z")

</div>

Hi. I’m trying to enable the following has\_many :through relationships  
on some models that, as you can see, these models have been namespaced  
which appears to be causing my grief:

====

## app/models/school/course.rb

class School::Course \< ActiveRecord::Base  
has\_many :registrations, :class\_name =\> ‘School::Registrations’  
has\_many :students, :through =\> :registrations  
end

## app/models/school/registration.rb

class School::Registration \< ActiveRecord::Base  
belongs\_to :course, :class\_name =\> ‘School::Course’  
belongs\_to :student, :class\_name =\> ‘School::Student’  
end

## app/models/school/student.rb

class School::Student \< ActiveRecord::Base  
has\_many :registrations, :class\_name =\> ‘School::Registration’  
has\_many :courses, :through =\> :regisrations  
end

====

The regular has\_many and belongs\_to relationships work fine. However,  
if I every try to use one of the has\_many :through relationships, I  
get:

ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find  
the association :regisrations in model School::Student  
from /home/kendall/namespaced/vendor/rails/activerecord/lib/  
active\_record/reflection.rb:285:in `check_validity!' from /home/kendall/namespaced/vendor/rails/activerecord/lib/ active_record/associations/has_many_through_association.rb:5:in`initialize’  
from /home/kendall/namespaced/vendor/rails/activerecord/lib/  
active\_record/associations.rb:1300:in `new' from /home/kendall/namespaced/vendor/rails/activerecord/lib/ active_record/associations.rb:1300:in`courses’

So my question is, does anyone know if/how I can get these  
relationships to actually work? I know rails’ support for namespaced  
models is sketchy. My use of namespaces isn’t a superfluous,  
aesthetic, or organizational whim. My real application for which this  
test was contrived needs, if at all possible, to use this feature. I’m  
using ruby 1.8.6 with rails 2.3.5.

Any help would be greatly appreciated!
