:through and STI

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:ininstance_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:insend’
from
./script/…/config/…/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:122:in
const_missing' from (eval):1:ininstance_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:incompute_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:inklass’
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:inload_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:inmethod_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:ineval_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:ineval_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:ineval_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:incatch’
from
/Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/1.8/irb.rb:69:in
`start’
f

Jeroen H. 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

Josh S. 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 :wink:

Thanks,

Jeroen