# :through difficulties

**URL:** <https://www.ruby-forum.com/t/through-difficulties/103451>\
**Category:** Rails\
**Created:** [May 6, 2007, 7:46am UTC](https://www.ruby-forum.com/t/through-difficulties/103451 "2007-05-06T07:46:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [May 6, 2007, 7:46am UTC](https://www.ruby-forum.com/t/through-difficulties/103451/1 "2007-05-06T07:46:04Z")

</div>

I’m trying to use :through on a many-to-many relationship.

I’ve got the following three models:

class User \< ActiveRecord::Base  
has\_many :authors  
has\_many :submissions, :through =\> :authors

class Author \< ActiveRecord::Base  
belongs\_to :submission  
belongs\_to :user

class Submission \< ActiveRecord::Base  
has\_many :authors  
has\_many :users, :through =\> :authors

I’ve also got test data for each of the models, but when I try to run  
either of the following in script/console I get the subsequent error:

user.submissions  
submission.users

NameError: undefined local variable or method

Any suggestions on how to figure out what I’ve done wrong?

---

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [May 6, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/through-difficulties/103451/2 "2007-05-06T12:36:33Z")

</div>

Have the same problem…

[http://www.ruby-forum.com/topic/107123](http://www.ruby-forum.com/topic/107123)

---

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [May 8, 2007, 3:09am UTC](https://www.ruby-forum.com/t/through-difficulties/103451/3 "2007-05-08T03:09:32Z")

</div>

On 06/05/2007, at 3:44 PM, will wrote:

> ```
> belongs_to :user
> 
> ```
> 
> class Submission \< ActiveRecord::Base  
> has\_many :authors  
> has\_many :users, :through =\> :authors

Do you have all the correct fields on these tables to support the  
relationships?

> I’ve also got test data for each of the models, but when I try to run  
> either of the following in script/console I get the subsequent error:
> 
> user.submissions  
> submission.users
> 
> NameError: undefined local variable or method

Can you post an exact log of what you’re typing in the console? I  
suspect you’re just misusing the relationships somehow.

Cheers,

Pete Y.

> **[Pete Yandell — Principal Engineer / Architect](https://notahat.com/)**
>
> Pete Yandell is an experienced Principal Software Engineer and Architect based in Melbourne, Australia.
