How to link multiple tables in Active Record

I have Four database tables:

student (id,student_name, grouping_id)
grouping (id, grouping_name)
subject_grouping (id,subject_id,grouping_id)
subject (id, subject_title)

In Student Model Class I have:

    public function getStuMasterGrouping()
{
    return $this->hasOne(Grouping::className(), ['id' => 'grouping_id']);
}

In Grouping Model Class I have:

    public function getSubjectGroupings()
{
    return $this->hasMany(SubjectGrouping::className(), ['id' => 'grouping_id']);
}  

In SubjectGrouping Model I have:

    public function getSubjectGroupingSubjects()
{
    return $this->hasOne(Subject::className(), ['id' => 'subject_id']);
}     

public function getSubjectGroupingGroupings()
{
    return $this->hasOne(Grouping::className(), ['id' => 'grouping_id']);
} 

And in Subject Model, I have:

    public function getSubjectSubjectGroupings()
{
    return $this->hasMany(SubjectGrouping::className(), ['id' => 'subject_id']);
} 

public static function getAvailableSubjects()
{
    $subjects = self::find()->orderBy('subject_title')->asArray()->all();
    $items = ArrayHelper::map($subjects, 'subject_id', 'subject_title');
    return $items;
}     

 function getSubjectTitles()
 {
	return ($this->subject_title);
 }  

In my Student Detail View, I want to display subject_title in subject table
student -> grouping -> subject_grouping -> subject

Since the subject table table is not directly linked to student table. How do I achieve this?