[5.x]: Eagerloading Matrix field EntryType overwrittenhandle
What happened?
Description
When an Entry has a Matrix field you can eager load this by using the with function. But within the matrix field you can rename the entry type handle. The with-function only excepts the original handle and not the re-written handle for that specific Matrix field.
Steps to reproduce
- Create an EntryType with the handle
exampleEntryType. Add an field with the handleexampleFieldto this FieldLayout - Create a Matrix field that uses this EntryType, call this field
exampleMatrixField - Create another Matrix field that use this EntryType, call this field
exampleMatrixField2 - In the second Matrix field press the horizontal-triple-dots besides the EntryType, rename the handle to
changedEntryType - Now try to eagerload this with
Entry::find()->with(['exampleMatrixField.exampleEntryType:exampleField'])and see that this works. - Now try to eagerload this
Entry::find()->with(['exampleMatrixField2.changedEntryType:exampleField'])and see that this does NOT works.
Expected behavior
When renaming handles for a specific Matrix field I expect that you can eagerload using the changed handle.
Expected:
Entry::find()->with(['exampleMatrixField2.changedEntryType:exampleField'])
This now would work, and not returning a Query object.
Actual behavior
Craft CMS version
5.8.21
PHP version
8.4.14
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
This is working as expected – see #17213. The original entry type handle should always be used when eager-loading.
You might want to switch to lazy eager-loading with eagerly(), and stop worrying about the with syntax altogether: