yii2-images
yii2-images copied to clipboard
eager loading
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?
Does someone have an idea of this?
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, 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()
/**
* @return \yii\db\ActiveQuery
*/
public function getImagesR()
{
return $this->hasOne(Image::className(), ['itemId' => 'id'])->where('modelName=:modelName AND isMain=1', [':modelName' => basename(__CLASS__)]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getImagesR()
{
return $this->hasOne(Image::className(), ['itemId' => 'id'])
->onCondition(['modelName' => $this->tableName()]);
}
but no placeHolder