Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eager loading #29

Open
drSun opened this issue Jul 1, 2015 · 5 comments
Open

eager loading #29

drSun opened this issue Jul 1, 2015 · 5 comments

Comments

@drSun
Copy link

drSun commented Jul 1, 2015

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?

@satoved
Copy link

satoved commented Sep 18, 2015

Does someone have an idea of this?

@CostaRico
Copy link
Owner

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.

@satoved
Copy link

satoved commented Sep 18, 2015

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()

@evgenybukharev
Copy link
Contributor

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

@archieDeveloper
Copy link

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

but no placeHolder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants