Answer the question
In order to leave comments, you need to log in
Why is Join not returning the contents of the second table?
Who knows why when join does not matter which inner or left it returns the result only from the first table with which the chain began:
$result = TableOne::find()
->select('table_one.user_id, table_two.*')
->innerJoin('table_two', 'table_one.post_id = table_two.post_id')
->where(['user_id' => Yii::$app->user->identity->id])->all();
dd($result );
createCommand()->getRawSql();
select('table_one.user_id, table_two.*')
Answer the question
In order to leave comments, you need to log in
You are working with ActiveRecord. When selecting from the database, Yii gets everything that you specified in the select.
However, further, when processing data from the database and forming models from them, Yii collects in the resulting array only the list of models for which the request was made.
To use data from the second table, set up model links and use with().
The data from the second table will be available via the $model->myRelation relationship
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question