# Has\_many and belongs\_to question... undefined method error

**URL:** <https://www.ruby-forum.com/t/has-many-and-belongs-to-question-undefined-method-error/113919>\
**Category:** Rails\
**Created:** [September 6, 2007, 5:48am UTC](https://www.ruby-forum.com/t/has-many-and-belongs-to-question-undefined-method-error/113919 "2007-09-06T05:48:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [September 6, 2007, 5:48am UTC](https://www.ruby-forum.com/t/has-many-and-belongs-to-question-undefined-method-error/113919/1 "2007-09-06T05:48:32Z")

</div>

I get this weird error message in the console when I try and navigate my  
relationship via Pool.gms.each()…

Here’s some cose.

class Gm \< ActiveRecord::Base  
belongs\_to :pools  
has\_many :teams  
has\_many :players, :through =\> :teams, :source =\> :nhl\_stat  
end

class Pool \< ActiveRecord::Base  
has\_many :gms  
end

Example…

> > pool = Pool.find(1)  
> > =\> #\<Pool:0xb7278424 @attributes={“last\_modified”=\>nil, “id”=\>“1”,  
> > “salary\_cap”=\>“40000000”, “pool\_name”=\>“RHP 07-08 Season - Career  
> > League”, “created”=\>nil}\>
> 
> > pool.gms.each() { |g| puts “GM: #{g.user\_name}\n” }  
> > NoMethodError: undefined method `pool' for Gm:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1235:in`method\_missing’  
> > from ./script/…/config/…/config/…/app/models/gm.rb:9  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:203:in  
> > `load_without_new_constant_marking' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:203:in`load\_file’

etc etc…

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [September 6, 2007, 5:56am UTC](https://www.ruby-forum.com/t/has-many-and-belongs-to-question-undefined-method-error/113919/2 "2007-09-06T05:56:51Z")

</div>

You’ve named your belongs \_to pools and it should be pool in your Gm  
class.

Hence rails is looking for pool and it’s not hence hence the undefined  
method.

Cam

On Sep 6, 1:48 pm, Jean N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
