You can use join
and on
just as you would in the DB query builder
$fileSessions = ORM::factory('filesession')
->with('subject')
->with('teacher')
->with('place')
->with('file')
->join(array('students','student'))->on('student.id', '=', 'file.student_id')
->where('payment_id','=',$payment_id)
->order_by('sessionDate','DESC')
->find_all();
or you can use the $_load_with
property on the file model. It does the loading automatically for you, so you don't need a second with call.
class Model_File extends ORM {
protected $_belongs_to = array
(
'student' => array ('foreign_key' => 'student_id' )
);
protected $_load_with = array('student');
}
When you load the File
model, you can access it by using $file->student
automatically, and on your Filesession
for example, it would be $filesession->file->student