ActiveRecord无法识别belongs_to关联

时间:2019-02-26 14:29:11

标签: ruby-on-rails ruby-on-rails-5

我有老师和学生的模型,学生fn f(v: &mut Vec<u32>) { // Remove all values in the vector v.clear(); // Fill the vector with 10 zeros v.resize(10, 0); } fn main() { let mut v: Vec<u32> = Vec::new(); f(&mut v); assert!(v == [0,0,0,0,0,0,0,0,0,0]); } 和老师belongs_to :teacher, optional: true

在rails控制台中,当我尝试has_many :students时,它将返回第11位老师的学生(如预期)

但是,当我尝试Teacher.find(11).students时会返回错误: Student.find(3).teachers

注意:第11位老师和第3位学生存在,并且在其关联的表中有记录

1 个答案:

答案 0 :(得分:1)

学生belongs_to :teacher,应该是

Student.find(3).teacher

teacher的注释单数形式

相关问题