我有这三种型号
学生有这三种模式,如性别,BloodType,地区。每个人都属于学生。
关联已在每个模型文件中设置。
在这种情况下,如果我想避免N+1问题,我如何编码?
是这样的吗?
@students = Student.find(:all).includes.includes(:gender, :blood_type, :prefecture)发布于 2013-07-18 01:21:09
您只需要.includes一次,并且您可以摆脱find(:all),因为Rails 3不需要它。
students = Student.includes(:gender, :blood_type, :prefecture)尽管如此,看起来这些只是查找表,如果您关心性能问题,我建议您将我的gem ClassyEnum作为潜在的替代。
https://stackoverflow.com/questions/17712893
复制相似问题