Answer the question
In order to leave comments, you need to log in
How to return Active Record as json with dependencies in Yii2?
Yii::$app->response->format = Response::FORMAT_JSON;
$model = Post::find()->with('comments')->all();
return $model;
Answer the question
In order to leave comments, you need to log in
I found the solution myself - to make a selection asArray()
$model = Post::find()->with('comments')->asArray()->all();
In this case, child objects are also translated into json.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question