I’ve 2 objects, Student and Homework. This is a one-to-many relationship where a student can have many Homeworks
I’m trying to use a .find method to retrieve all students and just one homework that he has.
I know I can use Student.find(:all, :include => :homeworks). But, this will return me the student and all it’s homeworks.
If your relation is one-to-many, you can’t pick just one without deciding which one should it be (e.g. first one, if you order them by ids). If so, you can use
#firstmethod on relation:If you mean pulling only one subject for each student from database it is more of SQL problem. You would have to write ‘ON’ clause that would pick single subject on your criterion.