Help searching/sorting related data

I have tables category, section & course. Categories belong to a section and a section is a course for a specific term.

Category has category.section_id

Section has section.course_id

I am trying to search by course.course_name.

I have already figured how to display course_name on category/index view…

on CategorySearch

[indent]added public $section;

added ‘section’ to safe under rules

added $query->joinWith(‘section’);[/indent]

on category/index

[indent]replace section_id with [‘attribute’=>‘section’ ,‘value’=>‘section.course.course_name’],[/indent]

So moving on to handle the search/sort,

I wanted to add this but it doesn’t work.


$dataProvider->sort->attributes['section'] = [

        'asc' => ['section.course.course_name' => SORT_ASC],

	'desc' => ['section.course.course_name' => SORT_DESC],

        ];

Please help me understand why on index I can access the course_name with section.course.course_name (I know there is a relation and a getCourse method) but Cannot do same for search/sort