Jean Nibee
2007-Sep-06 03:48 UTC
has_many and belongs_to question... undefined method error
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
cammo
2007-Sep-06 03:54 UTC
Re: has_many and belongs_to question... undefined method error
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 Nibee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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:1 235: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/dependen cies.rb:203:in > `load_without_new_constant_marking'' > from > /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependen cies.rb:203:in > `load_file'' > > etc etc... > > Thanks in advance. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---