Forum: Ruby on Rails :through and STI

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-03-27 22:07
(Received via mailing list)
Hi,


I'm trying to use :through and STI using the trunk version of Rails, but
I get the following error see bottom of this msg[1]

here are my classes.

class Player < ActiveRecord::Base
end

class Ladder < ActiveRecord::Base
   has_many :subscriptions
   has_many :players, :through => :subscriptions
end

class SingleLadder < Ladder
end

class Subscription < ActiveRecord::Base
   belongs_to :players
   belongs_to :ladders
end

Any ideas??

Jeroen


[1]

 >> Ladder.find(:first).players
NameError:
./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:89:in
`const_missing': uninitialized constant Players
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1197:in
`instance_eval'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:120:in
`const_missing'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:122:in
`send'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:122:in
`const_missing'
         from (eval):1:in `instance_eval'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1197:in
`instance_eval'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1197:in
`compute_type'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/reflection.rb:112:in
`send'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/reflection.rb:112:in
`klass'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:54:in
`find_target'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:116:in
`load_target'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:109:in
`method_missing'
         from
./script/../config/../config/../vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:47:in
`method_missing'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:296:in
`output_value'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:149:in
`eval_input'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:145:in
`signal_status'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:145:in
`eval_input'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:144:in
`each_top_level_statement'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:144:in
`eval_input'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:70:in
`start'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:69:in
`catch'
         from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:69:in
`start'
         f
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-27 22:16
Jeroen Houben wrote:
> class Subscription < ActiveRecord::Base
>    belongs_to :players
>    belongs_to :ladders
> end

> `const_missing': uninitialized constant Players

Your belongs_to associations should be singular:

class Subscription < ActiveRecord::Base
   belongs_to :player
   belongs_to :ladder
end

--josh
http://blog.hasmanythrough.com
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-03-28 08:08
(Received via mailing list)
Josh Susser wrote:
> class Subscription < ActiveRecord::Base
>    belongs_to :player
>    belongs_to :ladder
> end

Whoops! Well spotted - looking at your URL it seems you're the man to
ask ;-)

Thanks,

Jeroen
This topic is locked and can not be replied to.