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

[5.x]: Eager loading "owner" fields on Variants doesn't work #3817

Closed
webrgp opened this issue Dec 16, 2024 · 3 comments
Closed

[5.x]: Eager loading "owner" fields on Variants doesn't work #3817

webrgp opened this issue Dec 16, 2024 · 3 comments

Comments

@webrgp
Copy link

webrgp commented Dec 16, 2024

What happened?

Description

When trying to eager load the owner field on a Variant:

$variants = Variant::find()
    ->with([
        'owner.images',
    ])
    ->all();

Results in the following error:

craft\commerce\elements\Variant::setOwner(): Argument #1 ($owner) must be of type ?craft\base\ElementInterface, bool given, called in /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php on line 288

Replacing owner with product works as expected:

$variants = Variant::find()
    ->with([
        'product.images',
    ])
    ->all();

Craft CMS version

5.3.6

Craft Commerce version

5.2.1

PHP version

8.2.26

Operating system and version

Linux 6.10.14-linuxkit

Database type and version

MySQL 8.0.32

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Copy link

linear bot commented Dec 16, 2024

@lukeholder
Copy link
Member

Thanks for reporting. We have fixed this for the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev as 5.2.9.1",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release is out.

@nfourtythree
Copy link
Contributor

Commerce 5.2.10 has been released with this fix included.

Thanks!

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

No branches or pull requests

3 participants