Answer the question
In order to leave comments, you need to log in
How to select the desired column from a related table in AR Yii2?
$arr = Menu::find()->with([
'link' => function ($query) {
$query->select('menu_id, role_id');
}
])->asArray()->all();
public function getLink()
{
return $this->hasMany(Menu_role::className(), ['menu_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
$arr = Menu::find()
->with(['link'])
->select(['menu_role.menu_id', 'menu_role.role_id'])
->asArray()
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question