class Ladder < ActiveRecord::Base
has_many :players
has_many :users, :through => :players
end
class Player < ActiveRecord::Base
belongs_to :users
belongs_to :ladders
end
class User < ActiveRecord::Base
has_many :players
has_many :ladders, :through => :players
end
When I try the following code (on the console) I get an error:
@ladder = Ladder.find(1)
@ladder.users
I get this error:
NameError: uninitialized constant Ladder::Users
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:477:in `const_missing''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1360:in `compute_type''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/reflection.rb:125:in `send''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/reflection.rb:125:in `klass''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/associations/has_many_through_association.rb:115:in
`find_target''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/associations/association_proxy.rb:131:in `load_target''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/associations/association_proxy.rb:122:in
`method_missing''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/associations/has_many_through_association.rb:108:in
`method_missing''
from /opt/local/lib/ruby/1.8/irb.rb:298:in `output_value''
from /opt/local/lib/ruby/1.8/irb.rb:151:in `eval_input''
from /opt/local/lib/ruby/1.8/irb.rb:259:in `signal_status''
from /opt/local/lib/ruby/1.8/irb.rb:147:in `eval_input''
from /opt/local/lib/ruby/1.8/irb.rb:146:in `eval_input''
from /opt/local/lib/ruby/1.8/irb.rb:70:in `start''
from /opt/local/lib/ruby/1.8/irb.rb:69:in `catch''
from /opt/local/lib/ruby/1.8/irb.rb:69:in `start''
from /opt/local/bin/irb:13
What am I missing with the :through parameter? It''s driving me nuts.
-S
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-16 00:22 UTC
Re: has_many :through ... What am I missing?
Hi -- On Wed, 15 Aug 2007, Stuart Grimshaw wrote:> > class Ladder < ActiveRecord::Base > has_many :players > has_many :users, :through => :players > end > > class Player < ActiveRecord::Base > belongs_to :users > belongs_to :ladders > endMake those singular: belongs_to :user belongs_to :ladder David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
On Aug 16, 1:22 am, dbl...-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote:> Make those singular: > > belongs_to :user > belongs_to :ladderSmashing, thanks David --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---