Foreign Key Relations In Yii2 (Activerecord)

Off topic comment:

Are you serious? …

When you ask for help and post like 1000 lines of code - you could at least format all this lines with the CODE tags!

Sorry that had to be said.

Regards

isset($model->Territory ) && ! empty ( $model->Territory->territory_name ))

u just need to code for relation in your business model just like customer


public function getCustomerType() 

{ 

return $this->hasOne(CustomerType::className(), ['id' => 'business_cond_type_id']); 

}


public function getTerritoryname()

    {

        return $this->hasOne(Territory::className(), ['territory_type_id' => 'territory_type_id']);

    }



then in grid you can use below code.


if(isset($model->territory_type_id) && ! empty($model->territory_type_id))

   return $model->territoryname->territory_name;

regards,

webin

hi Kartik V,

       I want to show the particular role users only show in the dropdown using arrayhelper.

This is my view

‘promoter_id’ => [

‘type’ => Form::INPUT_DROPDOWN_LIST,

‘options’ => [‘prompt’ => ‘–’.Yii::t ( ‘app’, ‘Ventor Type’ ).’–’,],

‘items’ => ArrayHelper::map ( User::find ()->orderBy ( ‘username’ )->where([‘user_type_id’ => [13]])->asArray ()->all (), ‘id’, ‘username’ )]

promoter is a one of the role in user in my project.

So i want to filter the promoter users only show in above dropdown.

13 role id for promoter.i have directly hard coded here. but i want to get from the values in involve two tables.

this is totally different question which you raised in fk relation.

kindly create new post for other query.

and use code tag for php or html so viewer can read easily.

regards,

webin