Problem: when trying to
save!an instance of the join model in a
has_many :throughI was getting the following error:
NoMethodError (undefined method `eq' for nil:NilClass): app/models/user.rb:29:in `update_achievement' app/controllers/game_controller.rb:183:in `check_point' app/controllers/game_controller.rb:177:in `each' app/controllers/game_controller.rb:177:in `check_point'
has_many :throughwas originally a
has_and_belongs_to_manyrelation between the outer models, but since I needed to store more data in the join model I switched to a
has_many :through. The problem was that while I correctly set the relation in Rails, I forgot to add the
idcolumn in the join model. Adding the
idcolumn solved the problem.