How to do find() with includes() in Rails 3

Solution 1:

You just have to be more careful with the order of the methods in this case:

Student.includes(:teacher).find(12)

Solution 2:

Old question I know but just in case this helps someone...

Doing something like @student = Student.includes(:teacher).where(:id => 12) returns an array and so then using something such as @student.id doesn't work.

Instead you could do:

@student = Student.includes(:teacher).where(:id => 12).first

Although Student.includes(:teacher).find(12) should work, but you can use the where version if you need to search by other/multiple fields.

Solution 3:

Student.includes(:teacher).where(:id => 12)

should work.

Can we see your models ?