yii2: index page (with search) for relation one-to-many disaplying all fields

I’m quite new in Yii and I would like to know if this problem can be resolved in yii framework. I have three tables (A,B,C), A has the primary key ‘a_id’, B and C have a link to A (for example: b_a_id, c_a_id) that is a foreign key to ‘a_id’, relation A-B is one-to-one, relation A-C is one-to-many.

Is it possible in Yii in a simple way to have:

  1. for relation A - B, an index-page with search bar for every field that displays all the field of A and B

  2. for relation A - C, an index-page with search bar for every field that displays all the field of A and c

  3. the same for A - B - C

??

I’m not interested in CREATE/UPDATE/DELETE operation, only INDEX with SEARCH

I has been able to show A-B relation using B Controller/Model/View displaying the index page with A fields and B fields. I used a code like that below




<?= GridView::widget([

    'dataProvider' => $dataProviderB,

    'filterModel' => $searchModelB,

    'columns' => [

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

        'b_id',

        'b_field1',

        'b_field2', 


        'b_a_id.a_field1',    //field of B table

        'b_a_id.a_field2',

        'b_a_id.d_id.field1', //also field of D table liked to B


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

    ],

]); ?>



But It’s not available search box on ‘b_a_id.a_field1’, ‘b_a_id.a_field2’ neither obviously on ‘b_a_id.d_id.field1’. I know why. Because using foreign kwy i would like to show more than one field.

Do you have any suggestion for this kind of problem? Should I build a join sql command and display it? And so would the search available? Should I build a view in mysql database and generate model from view?

Please, reply with accuracy because I’m new in Yii

Thanks in advance

It should work without any additional sql. Have you built your DB scheme in InnoDB with a proper relations?

It works but the search is not available because all A fields are not in the $searchModelB (of B table), so the framework cannot add the filter for each columns of A tables.

If I would like to display only one field of A it would be sufficient add




public function search($params)

{

     

    $query = B::find();

 

    $query->joinWith('_Arelation');

    

    //...


    ->andFilterWhere(['like', 'A.field1', $this->a_id])


}



But I would like to show A.field1,2, etc…

How can I do?