我有这个关联:
has_many :exam_portions, -> { order :position }
belongs_to :exam
在考试部分有 before_save 回调:
before_create :proper_position
private
def proper_position
self.position = exam.exam_portions.count
end
当尝试建立关联时,会从 before_save 回调中引发以下错误:
NoMethodError: undefined method 'exam_portions' for nil:NilClass