S
S
Sergey Beloventsev2016-10-14 15:26:34
Yii
Sergey Beloventsev, 2016-10-14 15:26:34

What is the correct way to work with eager loading when using ListView widget?

I'm trying to organize work LIstViewwith links and eager loading like this I organize eager loading

$allGods=Gods::find()->with('prise','images','addfeilds')->all();

this is how I put it on display
<?= ListView::widget([
         'dataProvider'  => $productsDataProvider,
         'itemView'      => '_gods',
         'viewParams' => [
         'allGods'       => $allGods,]
 ]) ?>

I try to use it in the form
var_dump($model->images)
I receive an additional sqlrequest. I understand that I am doing something wrong. Do not tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-17
@Sergalas

when using eager loading, you will always have one additional request to load the relation (it doesn’t matter if you use with or joinWith), because the framework needs to somehow load the relation objects. Another question is how critical such requests are for your system and how much your architecture allows you to get rid of them. If your project uses one database and the presence of additional queries is too critical, use a regular join

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question