奇怪的问题has_many通过更新Rails中的关联

我从Ruby 2.1.2更新到Ruby 2.2.0并更新了链接到它的所有gem。 我有几个模型在彼此之间相互联系

class Question < ActiveRecord::Base belongs_to :course_version has_one :course, through: :course_version has_many :answer_questions has_many :answers, through: :answer_questions end class AnswerQuestion < ActiveRecord::Base belongs_to :answer belongs_to :question end class Answer < ActiveRecord::Base has_many :answer_questions has_many :questions, through: :answer_questions end 

如您所知,我们有问题可以得到答案并通过answer_questions来了解他们得到了什么。 在我更新Ruby之前,它工作得很好。 现在我做的事情……

 my_question.answers << my_answer 

它确实爆炸了

 NoMethodError: undefined method `name' for nil:NilClass /Users/Loschcode/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:80:in `cached_counter_attribute_name' /Users/Loschcode/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:76:in `has_cached_counter?' /Users/Loschcode/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.0/lib/active_record/associations/has_many_association.rb:84:in `update_counter' 

name是一个应该在questions表中的字段。 我花了几个小时试着理解这个……

仅供参考,我可以确认这是ActiveRecord和Ruby 2.2的问题。 我正在使用ActiveRecord 3.2,因为改为3-2稳定分支,问题就消失了。 我相信现在修复了4.x分支。 我在https://github.com/rails/rails/issues/18991上提出了一个问题。

我使用ruby 2.2.0时遇到了同样的问题。 对于特定项目,我回到了我之前的版本2.1.3,一切顺利。