# Got a problem with has\_many through

**URL:** <https://www.ruby-forum.com/t/got-a-problem-with-has-many-through/82382>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/got-a-problem-with-has-many-through/82382 "2007-01-19T16:29:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 19, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/got-a-problem-with-has-many-through/82382/1 "2007-01-19T16:29:58Z")

</div>

Hi,

today I’ve tried to replace one of my habtm associations with has\_many  
through but it just wouldn’t work. I’m sort of desperate, since I  
really don’t have a clue what the problem is.

Maybe someone’s got the time and patience to cast an eye on this.

These are my classes:

class Role \< ActiveRecord::Base  
has\_many :permissions  
has\_many :rights , :through =\> :permissions  
end

class Right \< ActiveRecord::Base  
has\_many :permissions  
has\_many :roles , :through =\> :permissions  
end

class Permission \< ActiveRecord::Base  
belongs\_to :rights  
belongs\_to :roles  
end

And this is the error that comes up(using the console):

> > role = Role.find\_first  
> > =\> #\<Role:0x9c2ad68 @attributes={“name”=\>“adfsadf”,  
> > “updated\_on”=\>“2007-01-08 15:41:00”, “id”=\>“3”, “active”=\>“0”,  
> > “created\_at”=\>“2007-01-08 12:34:00”}\>
> 
> > right = Right.find\_first  
> > =\> #\<Right:0x9c19554 @attributes={“updated\_on”=\>“2007-01-08 16:55:00”,  
> > “id”=\>“1”, “path”=\>"/rights", “active”=\>“0”, “created\_at”=\>“2007-01-08  
> > 12:34:00”}\>
> 
> > role.rights \<\< right  
> > NameError: uninitialized constant Role::Rights  
> > from  
> > ./script/…/config/…/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active\_support/dependencies.rb:478:in  
> > `const_missing' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1357:in`compute\_type’  
> > from  
> > ./script/…/config/…/config/…/vendor/rails/activerecord/lib/active\_record/reflection.rb:125:in  
> > `send' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/reflection.rb:125:in`klass’  
> > from  
> > ./script/…/config/…/config/…/vendor/rails/activerecord/lib/active\_record/associations/has\_many\_through\_association.rb:115:in  
> > `find_target' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:135:in`load\_target’  
> > from  
> > ./script/…/config/…/config/…/vendor/rails/activerecord/lib/active\_record/associations/has\_many\_through\_association.rb:54:in  
> > `\<\<’  
> > from (irb):3
> 
> > exit

Can anybody help me with this?

Greetings

Michael K.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/got-a-problem-with-has-many-through/82382/2 "2007-01-19T16:31:59Z")

</div>

> today I’ve tried to replace one of my habtm associations with has\_many  
> through but it just wouldn’t work. I’m sort of desperate, since I  
> really don’t have a clue what the problem is.

I had to use edge rails, apply fix for #6466, and use something like the  
following extension to get push, delete, and \<\< working properly

has\_many :referees\_out,  
:through =\> :refereeships,  
:source =\> :target\_user do  
def construct\_join\_attributes(associate)  
super.merge({:connection\_type =\> ‘R’})  
end  
end

–Ian
