Skip to content

Multi-element type eager loading maps #16972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2025

Conversation

brandonkelly
Copy link
Member

Description

Adds support for ElementInterface::eagerLoadingMap() to return mappings for multiple element types, or not specify element types at all if they aren’t known.

// existing format
return [
    'elementType' => MyType::class,
    'map' => [
        ['source' => 100, 'target' => 101],
        // ...
    ],
];

// multiple element type-specific mapping groups
return [
    [
        'elementType' => MyType1::class,
        'map' => [
            ['source' => 100, 'target' => 101],
            // ...
        ],
    ],
    [
        'elementType' => MyType2::class,
        'map' => [
            ['source' => 102, 'target' => 103],
            // ...
        ],
    ],
];

// types defined per mapping
return [
    'map' => [
        ['elementType' => MyType1::class, 'source' => 100, 'target' => 101],
        ['elementType' => MyType2::class, 'source' => 102, 'target' => 103],
    ],
];

// no types specified
return [
    'map' => [
        ['source' => 100, 'target' => 101],
        // ...
    ],
];

Needed to fix a bug where nested elements’ getOwner() and getPrimaryOwner() methods weren’t working properly if they had been loaded alongside other elements that didn’t share the same owner type (fully explained in #16960).

@olivierbon
Copy link
Member

That solves my use case 👍

@brandonkelly brandonkelly merged commit bf1ac0b into 5.7 Mar 28, 2025
@brandonkelly brandonkelly deleted the feature/multi-type-eager-loading branch March 28, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants