How to display data from the table matching the second table


I stopped thinking…

I would like to display in GridView data from the table Announcement where id is related with id_ann



id | title | description | price


id | id_ann | user_id

How to do it?

I tried this:

$query = Announcement::find()->joinWith('favourite')->where(['=', 'favourite.id_ann', $this->id]);

But I getting: No results…

Show your gridview code

It’s standard code

 <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

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






Probably there are not records that satisfy the condition

['=', 'favourite.id_ann', $this->id]

Who is $this->id ?

It works when I use this code:

 $query = Announcement::find()->innerJoinWith('favourite')->andFilterWhere(['>', 'favourite.id_ann', 'id']);

but when I change > to = it shows "No results…"