我有教师和学生模型,其中学生belongs_to :teacher, optional: true和教师has_many :students
在rails控制台中,当我尝试Teacher.find(11).students时,它会返回第11位教师的学生(不出所料)。
但是,当我尝试Student.find(3).teachers时,它返回一个错误:NoMethodError (undefined method 'teachers' for #<Student..>)
注意:第11位教师和第3位学生存在,并且在其关联表中有记录
发布于 2019-02-26 22:38:03
学生belongs_to :teacher,所以它应该是
Student.find(3).teacher关于teacher的奇异形式的注记
https://stackoverflow.com/questions/54887780
复制相似问题