indexBy Not Supported by AssociationOverride in Doctrine #7481

Closed
opened 2026-01-22 15:52:12 +01:00 by admin · 1 comment
Owner

Originally created by @ehibes on GitHub (Mar 1, 2025).

Problem Description

Currently, the indexBy attribute in Doctrine's OneToMany association is not supported by AssociationOverride. This limitation prevents developers from overriding the indexBy configuration in subclasses when extending a mapped superclass.

Detailed Example

Consider the following XML mapping in a mapped superclass:

<one-to-many
    field="channelPricings"
    target-entity="Sylius\Component\Core\Model\ChannelPricingInterface"
    mapped-by="productVariant"
    orphan-removal="true"
    index-by="channelCode"
>
    <order-by>
        <order-by-field name="id" />
    </order-by>

    <cascade>
        <cascade-all/>
    </cascade>
</one-to-many>

In this example, the channelPricings collection is indexed by channelCode.
However, when extending this mapped superclass, there is no straightforward way to override the indexBy attribute using AssociationOverride.

Originally created by @ehibes on GitHub (Mar 1, 2025). ### Problem Description Currently, the indexBy attribute in Doctrine's OneToMany association is not supported by AssociationOverride. This limitation prevents developers from overriding the indexBy configuration in subclasses when extending a mapped superclass. ### Detailed Example Consider the following XML mapping in a mapped superclass: ```xml <one-to-many field="channelPricings" target-entity="Sylius\Component\Core\Model\ChannelPricingInterface" mapped-by="productVariant" orphan-removal="true" index-by="channelCode" > <order-by> <order-by-field name="id" /> </order-by> <cascade> <cascade-all/> </cascade> </one-to-many> ``` In this example, the channelPricings collection is indexed by channelCode. However, when extending this mapped superclass, there is no straightforward way to override the indexBy attribute using AssociationOverride.
admin closed this issue 2026-01-22 15:52:12 +01:00
Author
Owner

@ehibes commented on GitHub (Mar 1, 2025):

To get around the problem, I completely redefined the relationship by specifying a different indexBy.

    #[ORM\OneToMany(
        mappedBy: 'productVariant',
        targetEntity: ChannelPricingInterface::class,
        cascade: ['all'],
        orphanRemoval: true,
        indexBy: 'id',
    )]
    #[ORM\OrderBy(['id' => 'ASC'])]
    protected $channelPricings;
@ehibes commented on GitHub (Mar 1, 2025): To get around the problem, I completely redefined the relationship by specifying a different indexBy. ```php #[ORM\OneToMany( mappedBy: 'productVariant', targetEntity: ChannelPricingInterface::class, cascade: ['all'], orphanRemoval: true, indexBy: 'id', )] #[ORM\OrderBy(['id' => 'ASC'])] protected $channelPricings; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7481