cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x]: Eagerloading Matrix field EntryType overwrittenhandle

Open Sven-am-impact opened this issue 2 months ago • 1 comments

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

  1. Create an EntryType with the handle exampleEntryType. Add an field with the handle exampleField to this FieldLayout
  2. Create a Matrix field that uses this EntryType, call this field exampleMatrixField
  3. Create another Matrix field that use this EntryType, call this field exampleMatrixField2
  4. In the second Matrix field press the horizontal-triple-dots besides the EntryType, rename the handle to changedEntryType
  5. Now try to eagerload this with Entry::find()->with(['exampleMatrixField.exampleEntryType:exampleField']) and see that this works.
  6. 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

Sven-am-impact avatar Dec 08 '25 15:12 Sven-am-impact

CMS-1717

linear[bot] avatar Dec 08 '25 15:12 linear[bot]

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:

brandonkelly avatar Dec 12 '25 17:12 brandonkelly