AttributeDriver ignores index and unique constraint definitions in Table attribute #7341

Closed
opened 2026-01-22 15:50:18 +01:00 by admin · 3 comments
Owner

Originally created by @DaDeather on GitHub (Mar 13, 2024).

Bug Report

Q A
BC Break no
Version >=2.9.x

Summary

Since the implementation of the AttributeDriver there's a bug that the properties of the Table attribute aren't counted in for the indices and unique constraints.

Current behavior

Currently setting the indices and unique constraints through the Table attribute results in them being ignored which therefore disallows the usage of nested attributes.

This is being handled here:
a809a71aa6/src/Mapping/Driver/AttributeDriver.php (L165-L173)

Before with annotations, this was possible and the code for the correct interpretation of these was implemented in the AnnotationDriver:
a809a71aa6/src/Mapping/Driver/AnnotationDriver.php (L137-L224)

How to reproduce

Creating an entity with the following attributes:

#[Orm\Entity()]
#[Orm\Table(
    'some_entities',
    indexes: [
        new Orm\Index(['some_column_1'], name: 'some_name_1'),
        new Orm\Index(['some_column_2'], name: 'some_name_2'),
    ],
    uniqueConstraints: [
        new Orm\UniqueConstraint('some_unique_constraint', ['some_column_3']),
    ],
)]
class SomeEntity
{
    // [...]
}

This wouldn't be handled by the AttributeDriver.

But doing it this way works:

#[Orm\Entity()]
#[Orm\Table('some_entities')]
#[Orm\Index(['some_column_1'], name: 'some_name_1')]
#[Orm\Index(['some_column_2'], name: 'some_name_2')]
#[Orm\UniqueConstraint('some_unique_constraint', ['some_column_3'])]
class SomeEntity
{
    // [...]
}

Expected behavior

The nested attribute variant should also work as expected if indices and / or unique constrains are defined within the Table attribute.

OR if this is unwanted behavior it should be removed to reduce confusions in terms of defining the table definitions.

Originally created by @DaDeather on GitHub (Mar 13, 2024). ### Bug Report | Q | A |------------ | ------ | BC Break | no | Version | >=2.9.x #### Summary Since the implementation of the `AttributeDriver` there's a bug that the properties of the `Table` attribute aren't counted in for the indices and unique constraints. #### Current behavior Currently setting the indices and unique constraints through the `Table` attribute results in them being ignored which therefore disallows the usage of nested attributes. This is being handled here: https://github.com/doctrine/orm/blob/a809a71aa6a233a6c82e68ebaaf8954adc4998dc/src/Mapping/Driver/AttributeDriver.php#L165-L173 Before with annotations, this was possible and the code for the correct interpretation of these was implemented in the `AnnotationDriver`: https://github.com/doctrine/orm/blob/a809a71aa6a233a6c82e68ebaaf8954adc4998dc/src/Mapping/Driver/AnnotationDriver.php#L137-L224 #### How to reproduce Creating an entity with the following attributes: ```php #[Orm\Entity()] #[Orm\Table( 'some_entities', indexes: [ new Orm\Index(['some_column_1'], name: 'some_name_1'), new Orm\Index(['some_column_2'], name: 'some_name_2'), ], uniqueConstraints: [ new Orm\UniqueConstraint('some_unique_constraint', ['some_column_3']), ], )] class SomeEntity { // [...] } ``` This wouldn't be handled by the `AttributeDriver`. But doing it this way works: ```php #[Orm\Entity()] #[Orm\Table('some_entities')] #[Orm\Index(['some_column_1'], name: 'some_name_1')] #[Orm\Index(['some_column_2'], name: 'some_name_2')] #[Orm\UniqueConstraint('some_unique_constraint', ['some_column_3'])] class SomeEntity { // [...] } ``` #### Expected behavior The nested attribute variant should also work as expected if indices and / or unique constrains are defined within the `Table` attribute. OR if this is unwanted behavior it should be removed to reduce confusions in terms of defining the table definitions.
admin closed this issue 2026-01-22 15:50:18 +01:00
Author
Owner

@DaDeather commented on GitHub (Mar 13, 2024):

Relates to:
PR - https://github.com/doctrine/orm/pull/9241
Issue - https://github.com/doctrine/orm/issues/9240

@DaDeather commented on GitHub (Mar 13, 2024): Relates to: PR - https://github.com/doctrine/orm/pull/9241 Issue - https://github.com/doctrine/orm/issues/9240
Author
Owner

@derrabus commented on GitHub (Mar 13, 2024):

We should remove those properties indexes and uniqueConstraints indeed as they don't have a function anymore. We should not provide two ways of achieving the same thing. Do you want to work on a PR?

@derrabus commented on GitHub (Mar 13, 2024): We should remove those properties `indexes` and `uniqueConstraints` indeed as they don't have a function anymore. We should not provide two ways of achieving the same thing. Do you want to work on a PR?
Author
Owner

@DaDeather commented on GitHub (Mar 13, 2024):

We should remove those properties indexes and uniqueConstraints indeed as they don't have a function anymore. We should not provide two ways of achieving the same thing. Do you want to work on a PR?

As we both agree on it being unnecessary to have 2 different approaches to the same, I've created a PR to remove these properties from the Table attribute instead to reduce unnecessary complexity and confusion 👍.

@DaDeather commented on GitHub (Mar 13, 2024): > We should remove those properties `indexes` and `uniqueConstraints` indeed as they don't have a function anymore. We should not provide two ways of achieving the same thing. Do you want to work on a PR? As we both agree on it being unnecessary to have 2 different approaches to the same, I've created a PR to remove these properties from the `Table` attribute instead to reduce unnecessary complexity and confusion :+1:.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7341