I have two related tables that I display through the gridview in the view. In the model, I use greedy loading. However, in the individual columns formed in columns => [...] I have repeatedly used duplicate queries in the database.
As a result, I get the following picture:
SELECT * FROM `event` WHERE `client_id`=293 F:\OSPanel\domains\es.loc\common\models\User.php:1229 F:\OSPanel\domains\es.loc\frontend\views\seller\crm\**lid.php:79** F:\OSPanel\domains\es.loc\backend\widgets\GridView\GridView.php:51 SELECT * FROM `event` WHERE `client_id`=293 F:\OSPanel\domains\es.loc\common\models\User.php:1229 F:\OSPanel\domains\es.loc\frontend\views\seller\crm\**lid.php:104** F:\OSPanel\domains\es.loc\backend\widgets\GridView\GridView.php:51 and so many times as in the view I have type records
User::clientId($model->id)->event[0]->next_date In the debug, I see that I have the same query in the database duplicated 5 times. As I understand it is not right and I have to remove this joint.
How can I contact the database once, so that in the gridview table within one row to form the data in the columns in my place, instead of the five queries formed through
User::clientId($model->id) It turned out 1 query, for example, at the first use, and in all subsequent columns of this row did this result be used?
The method looks like this:
public function clientId($id) { $res = User::find()->with('event')->where(['id' => $id])->all(); return $res; }
GridView- Roman Andreev