cms
cms copied to clipboard
Remove structureId query fallback, allow elements to lazy-set structureId
Description When an entry query does not contain a section or structureId, it will include a fallback to determine the structureId: https://github.com/craftcms/cms/blob/develop/src/elements/db/ElementQuery.php#L2503-L2526
This fallback is problematic if there are plugins that are leveraging structures, because it just joins on the matching element id, but there may be more rows with the same elementId.
This wouldn't happen with Craft's native use of structures, but theres nothing stopping others (Neo, etc).
I know there was an issue/discussion reporting this…but I can't find it.
DEV-210 Element queries can get incorrect structure data
When an entry query does not contain a section or structureId, it will include a fallback to determine the structureId: https://github.com/craftcms/cms/blob/develop/src/elements/db/ElementQuery.php#L2503-L2526
This fallback is problematic if there are plugins that are leveraging structures, because it just joins on the matching element id, but there may be more rows with the same elementId:
CleanShot 2022-01-13 at [email protected]
This wouldn't happen with Craft's native use of structures, but theres nothing stopping others.
@brandon suggested for 4.0 we just make it strict and require the structureIdbe set, but I'm not sure how that would work for queries that are cross-section/structure…seems like we need the join version still, it just needs to be more explicit so it would join on `sections.structureId`?