What happened?
First noticed this when I crated this: craftcms/docs#661 (comment)
Description
With this eager loading map:
{% set eager_load_map = [
[ 'navigation', { with: [
[ 'topLevel' ],
[ 'topLevel.detail:entry', { limit: 1 }],
[ 'elements' ],
[ 'elements.heading3:entry', { limit: 1 }],
[ 'elements.link:entry', { limit: 1 }],
]}]
] %}
{# example follow on call #}
[entryQuery].with(eager_load_map).all()
navigation is an Matrix field in an Entry type on a section dedicated to being the site's main navigation
navigation.topLevel is a Matrix field holding a single block within navigation
navigation.elements is a Matrix field holding many blocks within navigation
The entry within the topLevel & elements Matrix blocks is an Entry Field that in each appearance holds a single entry representing the target of the navigation item.
Note that there are (at least) 2 different Entry types attached to the elements Matrix block but they all have an entry Entry Field.
The issue is that depending how you adjust the map (these bits: navigation.elements:link.entry & navigation.elements:heading3.entry) only 1 of them is ever actually eager loaded. I have tried many different iterations of how to lay this map out but they never all get eager loaded.
My guess here is that navigation.elements:link.entry & navigation.elements:heading3.entry are internally being treated as the same thing, effectively resolving to navigation.elements.entry but only ever applying to one the entry types on the Matrix block - it looks like the order they are defined in the map make no difference.
For reference, the same map, doing a working eager load on Craft 4 is this:
{% set eager_load_map = [
[ 'navigation' ],
[ 'navigation.topLevel' ],
[ 'navigation.topLevel.entry', { limit: 1 } ],
[ 'navigation.elements' ],
[ 'navigation.elements.heading:entry', { limit: 1 } ],
[ 'navigation.elements.link:entry', { limit: 1 } ]
] %}
Trying this on v5 doesn't work in the same way as the first snippet doesn't!
Steps to reproduce
- Matrix on an entry type in a section called
navigation containing:
- Another Matrix with a single block
topLevel containing an entry field called entry
- Another Matrix with multiple blocks 2 or more of which should contain an entry field called
entry.
- Attempt to eager load
navigation, topLevel.entry and navigation.[eitherEntryType].entry
Expected behavior
All the things gets eager loaded.
Actual behavior
Some of the things get eager loaded.
Craft CMS version
5.4.4
PHP version
8.3.7
What happened?
First noticed this when I crated this: craftcms/docs#661 (comment)
Description
With this eager loading map:
{% set eager_load_map = [ [ 'navigation', { with: [ [ 'topLevel' ], [ 'topLevel.detail:entry', { limit: 1 }], [ 'elements' ], [ 'elements.heading3:entry', { limit: 1 }], [ 'elements.link:entry', { limit: 1 }], ]}] ] %} {# example follow on call #} [entryQuery].with(eager_load_map).all()navigationis an Matrix field in an Entry type on a section dedicated to being the site's main navigationnavigation.topLevelis a Matrix field holding a single block withinnavigationnavigation.elementsis a Matrix field holding many blocks withinnavigationThe
entrywithin thetopLevel&elementsMatrix blocks is an Entry Field that in each appearance holds a single entry representing the target of the navigation item.Note that there are (at least) 2 different Entry types attached to the
elementsMatrix block but they all have anentryEntry Field.The issue is that depending how you adjust the map (these bits:
navigation.elements:link.entry&navigation.elements:heading3.entry) only 1 of them is ever actually eager loaded. I have tried many different iterations of how to lay this map out but they never all get eager loaded.My guess here is that
navigation.elements:link.entry&navigation.elements:heading3.entryare internally being treated as the same thing, effectively resolving tonavigation.elements.entrybut only ever applying to one the entry types on the Matrix block - it looks like the order they are defined in the map make no difference.For reference, the same map, doing a working eager load on Craft 4 is this:
{% set eager_load_map = [ [ 'navigation' ], [ 'navigation.topLevel' ], [ 'navigation.topLevel.entry', { limit: 1 } ], [ 'navigation.elements' ], [ 'navigation.elements.heading:entry', { limit: 1 } ], [ 'navigation.elements.link:entry', { limit: 1 } ] ] %}Trying this on v5 doesn't work in the same way as the first snippet doesn't!
Steps to reproduce
navigationcontaining:topLevelcontaining an entry field calledentryentry.navigation,topLevel.entryandnavigation.[eitherEntryType].entryExpected behavior
All the things gets eager loaded.
Actual behavior
Some of the things get eager loaded.
Craft CMS version
5.4.4
PHP version
8.3.7