Andrew Kaspick wrote:
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?
Andrew, for this example you should leave the class_name option off the through association declaration. The class_name option for through assocations is really a source_association_name option. The correct class of the associated objects is picked up from the class of the source belongs_to association. This will definitely confuse a lot of people unless either the special use of class_name is documented, or the class_name option is made invalid on through associations and replaced with a source_association_name option. Mark _______________________________________________ Rails-core mailing list [email protected] http://lists.rubyonrails.org/mailman/listinfo/rails-core
