How to display data from the table matching the second table

Hi.

I stopped thinking…

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

Tables:

Announcement

id | title | description | price

Favourite

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'],

'id',

'title',

'description',

'price'

]);?>

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…"