Answer the question
In order to leave comments, you need to log in
How to get all fields of their related table in yii2?
How to get rest of fields from related table in yii2?
Right now I am getting one field like this -
public function getBase() {
return $this->hasOne(Base::className(), [ 'id' => 'base_id' ]);
}
public function getIp() {
return $this->base->ip;
}
Answer the question
In order to leave comments, you need to log in
As you can see, the connection goes by the id of the base, I get the ip with the getIp function. It turns out for each field such function is necessary?
$models = Mymodel::find()->all();
foreach($models as $one){
if(isset($one->base)){
echo $one->base->ip;
echo $one->base->name;
echo $one->base->eshe_chto-to;
}
}
public function getIp() {
return ($this->base)?$this->base->ip:"нет данных";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question