gridview sort

hi there i have 3 bellow tables

ads(id, user_id)

tender(id,user_id, ads_id)

user(id)

the tender controller , the action index changed like bellow:




        $dataProvider = new ActiveDataProvider([

            'query' => Tender::find()->joinWith(['user', 'ads']),

        ]);


		

		

		$dataProvider->setSort([

			'attributes' => 

				array_merge(

					$dataProvider->sort->attributes, [

						'user.name',

						'ads.name',

						'ads.user.name',

					]),

		]);


        return $this->render('index', [

            'dataProvider' => $dataProvider,

        ]);



and the view file is :




 <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],


            'user.name',

            'ads.name',

            'amount',

            'ads.user.name',


            ['class' => 'yii\grid\ActionColumn'],

        ],

    ]); ?>



everything about result in gridview and sorting is ok except ‘ads.user.name’. when i click to sort that column the bellow error will show:




Column not found: 1054 Unknown column 'ads.user.name' in 'order clause'

The SQL being executed was: SELECT `tender`.* FROM `tender` LEFT JOIN `user` ON `tender`.`user_id` = `user`.`id` LEFT JOIN `ads` ON `tender`.`ads_id` = `ads`.`id` ORDER BY `ads`.`user`.`name` LIMIT 20



thanks in advanced

in SearchMOdel

u have to code for that field:ads.user.name


 public $countrySort;

  1. define in rules too;

  2. for sorting:




$dataProvider->setSort([

        'attributes' => [

            'stateId',

            'stateName',

            'countrySort' => [

                'asc' => ['tbl_country.countryName' => SORT_ASC],

                'desc' => ['tbl_country.countryName' => SORT_DESC], 

                'default' => SORT_ASC

            ],

            

        ]

    ]);

  1. Filter

$query->andFilterWhere(['like', 'tbl_country.countryName', $this->countrySort]);