What happened?
Description
Since 5.11.0, accessing .owner on a nested (Matrix-owned) entry in Twig can return an ElementCollection instead of the owner element, so any chained field access throws. Example:
BadMethodCallException: Method craft\elements\ElementCollection::afbeelding does not exist.
This worked fine in 5.10.14. Claude reports: "It looks like getOwner() now eager-loads owners for the whole query result, and Element::__get prefers the eager-loaded set over the getter — hence the collection."
Maybe getOwner() is the better way, and the workaround is to use that instead, but given that the trait's docblock declares @property ElementInterface|null $owner this looks like an unintended consequence of recent changes? Might affect others as well.
Steps to reproduce
- Query nested Matrix entries directly, e.g.
craft.entries.type('myMatrixEntryType').all()
- Loop the results and access
{{ entry.owner.title }} (or any field on the owner)
- Once one row's owner resolution triggers the eager-load, subsequent rows'
.owner returns an ElementCollection and you get chained access throws
Expected behavior
entry.owner returns the owner element (or null), as documented in the docblock
Actual behavior
entry.owner returns a craft\elements\ElementCollection
Craft CMS version
5.11.0
PHP version
8.4.25
What happened?
Description
Since 5.11.0, accessing .owner on a nested (Matrix-owned) entry in Twig can return an ElementCollection instead of the owner element, so any chained field access throws. Example:
This worked fine in 5.10.14. Claude reports: "It looks like
getOwner()now eager-loads owners for the whole query result, andElement::__getprefers the eager-loaded set over the getter — hence the collection."Maybe getOwner() is the better way, and the workaround is to use that instead, but given that the trait's docblock declares
@property ElementInterface|null $ownerthis looks like an unintended consequence of recent changes? Might affect others as well.Steps to reproduce
craft.entries.type('myMatrixEntryType').all(){{ entry.owner.title }}(or any field on the owner).ownerreturns anElementCollectionand you get chained access throwsExpected behavior
entry.ownerreturns the owner element (or null), as documented in the docblockActual behavior
entry.ownerreturns acraft\elements\ElementCollectionCraft CMS version
5.11.0
PHP version
8.4.25