Yii2 Dynamic Relational, Eager Loading

[Solved] Yii2 Dynamic Relational, Eager Loading | Php Frameworks Yii - Code Explorer | yomemimo.com
Question : Yii2 Dynamic Relational, Lazy loading

Answered by : rusik

// SELECT * FROM `customer` LIMIT 100
$customers = Customer::find()->limit(100)->all();
foreach ($customers as $customer) { // SELECT * FROM `order` WHERE `customer_id` = ... $orders = $customer->orders;
}

Source : https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#relational-data | Last Update : Mon, 28 Feb 22

Question : Yii2 Dynamic Relational, Eager loading

Answered by : rusik

// SELECT * FROM `customer` LIMIT 100;
// SELECT * FROM `orders` WHERE `customer_id` IN (...)
$customers = Customer::find() ->with('orders') ->limit(100) ->all();
foreach ($customers as $customer) { // no SQL executed $orders = $customer->orders;
}

Source : https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#relational-data | Last Update : Mon, 28 Feb 22

Answers related to Yii2 Dynamic Relational, Eager loading

Code Explorer Popular Question For Php Frameworks Yii