Hi there,
I've recently started using the :through option on has_many
associations and for the most part I've had no issues, but I've seemed
to run into a bit of a roadblock with a specific case outlined below.
I'm not sure if this is a bug in the feature or simply lack of user
understandings.
Anyway, here's my scenario:
I have 3 classes for the join. Showing just the one side of the join
with the 2 classes (the 3rd class is called User)...
class PlayerStatistic < ActiveRecord::Base
belongs_to :game
belongs_to :user
end
class Game < ActiveRecord::Base
has_many :statistics, :class_name => 'PlayerStatistic'
has_many :players, :through => :statistics,
:class_name => 'User'
end
I can do..
g = Game.find(:first)
g.statistics
g.players
g.statistics[0].user
as expected.
Now if I change the name of my association from user to player...
class PlayerStatistic < ActiveRecord::Base
belongs_to :game
belongs_to :player, :class_name => 'User' # <-- this line different
end
# still the same code as above
class Game < ActiveRecord::Base
has_many :statistics, :class_name => 'PlayerStatistic'
has_many :players, :through => :statistics,
:class_name => 'User'
end
I can do..
g = Game.find(:first)
g.statistics
g.statistics[0].player # player now instead of user works
but no longer can call..
g.players
This fails with a
ActiveRecord::HasManyThroughSourceAssociationNotFoundError exception.
Is this a bug or am I simply missing something here?
Thanks,
Andrew
_______________________________________________
Rails-core mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-core