Namespaced models with has_many :through

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:ininitialize’
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:incourses’

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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs