# Noobie question about has\_many :through

**URL:** <https://www.ruby-forum.com/t/noobie-question-about-has-many-through/111093>\
**Category:** Rails\
**Created:** [August 2, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/noobie-question-about-has-many-through/111093 "2007-08-02T16:29:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbrackenridge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@pbrackenridge](https://www.ruby-forum.com/u/pbrackenridge)\
**Post date:** [August 2, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/noobie-question-about-has-many-through/111093/1 "2007-08-02T16:29:16Z")

</div>

First of all, I am a bit of a noob so sorry if this is a very simple  
question.

Basically I want to model the relationship between a User (U) and a  
Questionnaire(Qu). A Qu  
has one Subject (the user that the questionnaire is about) and many  
Reviewers (people/users that work  
with the User answering the Qu about the U).

My migrations can be found [here](http://pastie.caboo.se/%0A84359) and models ca be  
found

I tried the following in script/console

`
quest1 = Questionnaire.create(:title => "First One")
sub1 = User.create(:login => “sub1”, :email => “removed_email_address@domain.invalid”, :name
=> “Subject 1”, :password => “password”, :password_confirmation =>
“password”)
rev1 = User.create(:login => “rev1”, :email => “removed_email_address@domain.invalid”, :name
=> “reviewer 1”, :password => “password”, :password_confirmation =>
“password”)
rev2 = User.create(:login => “rev2”, :email => “removed_email_address@domain.invalid”, :name
=> “reviewer 2”, :password => “password”, :password_confirmation =>
“password”)
`

`a_sub = Subjectships.create(:user_id => sub1.id, :questionnaire_id =>
quest1.id)
a_rev1 = Reviewerships.create(:user_id => rev1.id, :questionnaire_id
=> quest1.id)
a_rev2 = Reviewerships.create(:user_id => rev2.id, :questionnaire_id
=> quest1.id)
`

but when I tried `quest1.subjects`

I get the following error  
  
NameError: uninitialized constant Questionnaire::Subjectship  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/…/…/activesupport/lib/  
active\_support/dependencies.rb:477:in `const_missing' from /Users/paulbrackenridge/Rails/projects/work/enabling development/ED/vendor/rails/activerecord/lib/active_record/base.rb: 1479:in `compute\_type’  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/active\_record/  
reflection.rb:125:in `send' from /Users/paulbrackenridge/Rails/projects/work/enabling development/ED/vendor/rails/activerecord/lib/active_record/ reflection.rb:125:in `klass’  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/active\_record/  
reflection.rb:169:in `source_reflection' from /Users/paulbrackenridge/Rails/projects/work/enabling development/ED/vendor/rails/activerecord/lib/active_record/ reflection.rb:169:in `collect’  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/active\_record/  
reflection.rb:169:in `source_reflection' from /Users/paulbrackenridge/Rails/projects/work/enabling development/ED/vendor/rails/activerecord/lib/active_record/ reflection.rb:178:in `check\_validity!’  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/active\_record/  
associations/has\_many\_through\_association.rb:6:in `initialize' from /Users/paulbrackenridge/Rails/projects/work/enabling development/ED/vendor/rails/activerecord/lib/active_record/ associations.rb:1048:in `new’  
from /Users/paulbrackenridge/Rails/projects/work/enabling  
development/ED/vendor/rails/activerecord/lib/active\_record/  
associations.rb:1048:in `subjects’  
from (irb):18

I’m not quite at home with the error messages yet, so if anyone could  
give me a hand I would  
be eternally greatfull 🙂

Cheers,

P

---

<div class="post-metadata">

**Author:** ![pbrackenridge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@pbrackenridge](https://www.ruby-forum.com/u/pbrackenridge)\
**Post date:** [August 2, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/noobie-question-about-has-many-through/111093/2 "2007-08-02T17:13:26Z")

</div>

Right, managed to sort it (boy what a noobie mistake that was ☹ )

I removed the pluralisation from the model names (god knows how I  
managed  
to add that!!) and added a the :source option to my :through clauses.  
My  
models now look something like this…

`
  has_many :reviewerships
  has_many :reviewers, :through => :reviewerships, :source => :user
has_many :subjectships
has_many :subjects, :through => :subjectships, :source => :user
`
