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 of duplicated field with changed handle #15890

Closed
alex-brukhty opened this issue Oct 13, 2024 · 4 comments
Closed

[5.x]: Eager loading of duplicated field with changed handle #15890

alex-brukhty opened this issue Oct 13, 2024 · 4 comments
Labels

Comments

@alex-brukhty
Copy link

alex-brukhty commented Oct 13, 2024

What happened?

Description

When duplicating the same Asset field (giving different handles) to use on the same entry type. The querying with the eager loading function gives the content of the first original field.

{% set logo = featured ? entry.thumbnail.eagerly().one() : entry.logo.eagerly().one() %}
{% set grid = entry.grid.eagerly().one %}

The query above always returns contents of entry.logo for both logo and grid even for entry.thumbnail if featured is true, and I think this field was first assigned to the entry type, or maybe it's just first in the field layout.

Steps to reproduce

  1. Assigng same Asset field multiple times to an entry type (it will assign diff handles automatically)
  2. Populate asset field with content
  3. Query these asset fields in template using eagerly()

Expected behavior

To return proper content for each field with different field handle using eagerly()

Actual behavior

Returns the content of first Asset field in the filed layout for all other duplicates of this field.

Craft CMS version

5.4.7.1

PHP version

8.3

Operating system and version

ddev

Database type and version

postgres 14

Image driver and version

@brandonkelly
Copy link
Member

Thanks for reporting that! Just tagged Craft 5.4.8 with a fix.

@naboo
Copy link

naboo commented Oct 25, 2024

@brandonkelly I'm still experiencing this issue running 5.4.9 but with a sub-relation entry. Like this:

{% set collection = entry.collectionEntry.eagerly().one() %}
{% set relatedEntries = collection.relatedEntries.eagerly().all() %}
{% set moreRelatedEntries = collection.moreRelatedEntries.eagerly().all() %}

relatedEntries and moreRelatedEntries pull the same entries but only entries are selected for field "moreRelatedEntries". They are both the same field added to the entry type multiple times.

@brandonkelly
Copy link
Member

@naboo Can you post a new issue with details about your content model so we can try to reproduce?

@naboo
Copy link

naboo commented Nov 22, 2024

Done: #16191

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

3 participants