yii2-images icon indicating copy to clipboard operation
yii2-images copied to clipboard

eager loading

Open drSun opened this issue 9 years ago • 5 comments

Hello! Thank you for your work. Is there any way to use eager loading? If I call getUrl() several times on one page, there are more than 50 SQL statements being executed! It's really bad.

Can I use smth like ->with('images'), using your module?

drSun avatar Jul 01 '15 07:07 drSun

Does someone have an idea of this?

satoved avatar Sep 18 '15 13:09 satoved

You know, it's very strange, because I used this module in several projects and everything was fine. If u create some test project with such trouble I could check it out and fix.

CostaRico avatar Sep 18 '15 15:09 CostaRico

CostaRico, thanks for reply.

Everything is great while working with one instance of model. But it goes wrong, when I'm trying to get a couple of images from a lot of instances.

For example, Book have a Category. And I'm trying to show 20 thumbnails from 20 books in one category. So in foreach cycle there will be 20 SQL requests for every Book by every $book->getImage()

satoved avatar Sep 18 '15 16:09 satoved

/**
 * @return \yii\db\ActiveQuery
 */
public function getImagesR()
{
    return $this->hasOne(Image::className(), ['itemId' => 'id'])->where('modelName=:modelName AND isMain=1', [':modelName' => basename(__CLASS__)]);
}

evgenybukharev avatar Nov 16 '15 11:11 evgenybukharev

/**
 * @return \yii\db\ActiveQuery
 */
public function getImagesR()
{
    return $this->hasOne(Image::className(), ['itemId' => 'id'])
        ->onCondition(['modelName' => $this->tableName()]);
}

but no placeHolder

archieDeveloper avatar Feb 02 '16 18:02 archieDeveloper