Answer the question
In order to leave comments, you need to log in
Yii2. Why does it output NULL on eager loading?
Good afternoon!
The User model has a relationship:
public function getMessage () {
return $this->hasMany ( Message::className () , [ 'to_id' => 'id' ] );
}
public function getUser() {
return $this->hasOne(User::className(), ['id' => 'to_id']);
}
$models = Message::find()->with('user')->where(['from_id' => Yii::$app->user->identity->id , 'type' => 2])->orderBy([ 'time' => SORT_ASC ])->limit(15)->all();
foreach ($models as $model) {
var_dump($model->user)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question