99m*_*les 42 ruby-on-rails ruby-on-rails-3
我正在尝试这样做,但它不起作用.我如何在Rails 3中执行此操作?
Student.find(12).includes(:teacher)
Rob*_*her 80
在这种情况下,您只需要更加小心方法的顺序:
Student.includes(:teacher).find(12)
老问题我知道,但以防这有助于某人...
做类似的事情@student = Student.includes(:teacher).where(:id => 12)返回一个数组,然后使用像这样的东西@student.id不起作用.
相反,你可以这样做:
@student = Student.includes(:teacher).where(:id => 12).first
虽然Student.includes(:teacher).find(12)应该可以使用,但是where如果需要通过其他/多个字段进行搜索,则可以使用该版本.
| 归档时间: | 
 | 
| 查看次数: | 23481 次 | 
| 最近记录: |