Tabular Form with Multiple Models

How do I get a Kartik Tabular Form working with Multiple Models?

From the Controller:


public function actionDepositUpdate($id) {

        $payment = new Payment();

        

        $dataProvider = new ActiveDataProvider([

            'query' => Payment::find()

                ->where(['cash_receipt_id' => $id])

                ->joinWith(['paymentLoads']),

        ]);

        

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

            'titles' => $this->createTitlesDeposits(),

            'dataProvider' => $dataProvider,

            'attributes' => $payment->createDepositColumns(),

        ]);

    }

From the Model ‘Payment’:




    public function getPaymentLoads()

    {

        return $this->hasMany(PaymentLoads::className(), ['payment_id' => 'id']);

    }

  

    public function createDepositColumns() {

        $gridColumns = [];

        

         $gridColumns = array_merge($gridColumns, 

            [

                [   'attribute'=>'id',

                    'type' => 'staticInput',

                    'value' => function ($model) { 

    // this one works

                        return $model->id;

                    },

                ],

                

                [   'attribute' => 'paymentLoads.departure_nav_waypt_airport_id',

                    'type' => 'staticInput',

                    'value' => function ($model) { 

    // this one doesn't work

                        return $model->paymentLoads->departure_nav_waypt_airport_id;

                    },


                ],

                

                

            ]);

        

         return $gridColumns;

    }

From the View:




        $form['main'] = ActiveForm::begin();


        $tabular =  TabularForm::widget([

            'dataProvider'=>$dataProvider,

            'form'=>$form['main'],

            'attributes'=>$attributes,

            'gridSettings' => [

                'panel' => [

                        'type' => 'info',

                        'heading' => Html::tag('div',$titles->panelIndex(),['class' => 'pull-left']),

                    ],

            ],

        ]);

        echo $tabular;

This configuration results in the following error:

PHP Notice – yii\base\ErrorException

Trying to get property of non-object


return $model->paymentLoads->departure_nav_waypt_airport_id;

Question is, how do I get one field from each model to show up on the Tabular Form?

Bump …