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]: PHP error when eager loading an element owner that is not the same element type as the nested element #16339

Closed
lukeholder opened this issue Dec 17, 2024 · 1 comment
Labels

Comments

@lukeholder
Copy link
Member

lukeholder commented Dec 17, 2024

What happened?

Description

The following code will cause the error:

{% set addresses = craft.addresses.with(['owner']).all() %}

This is due to

'elementType' => get_class(reset($sourceElements)),

expecting that the element type for the eager loading of the parent is the same element type as the source element.

Adding a matrix field to a category element and using this query can also cause the error:

{% set matrix = craft.entries.with(['owner']).all() %}

Since the category is not an entry element type.

Steps to reproduce

Add this code to a front-end template:

{% set addresses = craft.addresses.with(['owner']).all() %}

Actual behavior

PHP error

Related issue:

craftcms/commerce#3817

Fixed manually in Commerce with:

craftcms/commerce@5eacab1

Craft CMS version

5.x

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

@lukeholder lukeholder added the bug label Dec 17, 2024
@lukeholder lukeholder changed the title [5.x]: PHP error when eager loading owner that is not the same element type as the nested element [5.x]: PHP error when eager loading an element owner that is not the same element type as the nested element Dec 17, 2024
@brandonkelly
Copy link
Member

Thank you sir! Fixed in Craft 5.5.7.

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

No branches or pull requests

2 participants