MappingException with report_fields_where_declared: true #7287

Closed
opened 2026-01-22 15:49:12 +01:00 by admin · 9 comments
Owner

Originally created by @BackNot on GitHub (Dec 20, 2023).

Bug Report

Q A
BC Break yes
Version 2.17.1

Summary

With the option report_fields_where_declared I get error

Duplicate definition of column 'id' on entity 'App\Entity\A' in a field or discriminator column mapping.

Reproduce

I updated the doctrine recipe and set this option to true:

report_fields_where_declared: true

I have the following class hierarchy:

[ORM\Table(name: "`classa`")]
#[ORM\Entity(repositoryClass: "App\Repository\ARepository")]
#[ORM\HasLifecycleCallbacks]
class A extends B 
{

   ... 
}

#[ORM\Table(name: "`classb`")]
#[ORM\Entity(repositoryClass: "App\Repository\BRepository")]
#[ORM\HasLifecycleCallbacks]
#[ORM\InheritanceType("JOINED")]
#[ORM\DiscriminatorColumn(name: "dType", type: Types::STRING)]
class B extends C
{
  
    ....
}
abstract class C 
{
     #[Id, ORM\GeneratedValue(strategy: 'AUTO')]
    #[ORM\Column(name: 'id', type: Types::INTEGER)]
    protected ?int $id = null;
}

I understand that with this setting if I have the property "id" both in my parent and child the error will be shown. But currently I just inherit it and I do not overwrite it anywhere.

If I drop class C and put this field in class B this error is not triggered.

Originally created by @BackNot on GitHub (Dec 20, 2023). ### Bug Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.17.1 #### Summary With the option report_fields_where_declared I get error ``` Duplicate definition of column 'id' on entity 'App\Entity\A' in a field or discriminator column mapping. ``` #### Reproduce I updated the doctrine recipe and set this option to true: ``` report_fields_where_declared: true ``` I have the following class hierarchy: ``` [ORM\Table(name: "`classa`")] #[ORM\Entity(repositoryClass: "App\Repository\ARepository")] #[ORM\HasLifecycleCallbacks] class A extends B { ... } ``` ``` #[ORM\Table(name: "`classb`")] #[ORM\Entity(repositoryClass: "App\Repository\BRepository")] #[ORM\HasLifecycleCallbacks] #[ORM\InheritanceType("JOINED")] #[ORM\DiscriminatorColumn(name: "dType", type: Types::STRING)] class B extends C { .... } ``` ``` abstract class C { #[Id, ORM\GeneratedValue(strategy: 'AUTO')] #[ORM\Column(name: 'id', type: Types::INTEGER)] protected ?int $id = null; } ``` I understand that with this setting if I have the property "id" both in my parent and child the error will be shown. But currently I just inherit it and I do not overwrite it anywhere. If I drop class C and put this field in class B this error is not triggered.
admin closed this issue 2026-01-22 15:49:13 +01:00
Author
Owner

@derrabus commented on GitHub (Dec 20, 2023):

cc @mpdude

@derrabus commented on GitHub (Dec 20, 2023): cc @mpdude
Author
Owner

@mpdude commented on GitHub (Dec 21, 2023):

The C class contains mapping information but is not an entity nor a mapped superclass. Is that correct?

@mpdude commented on GitHub (Dec 21, 2023): The C class contains mapping information but is not an entity nor a mapped superclass. Is that correct?
Author
Owner

@mpdude commented on GitHub (Dec 21, 2023):

Also, you’re relying on an autogenerated discriminator map?

@mpdude commented on GitHub (Dec 21, 2023): Also, you’re relying on an autogenerated discriminator map?
Author
Owner

@BackNot commented on GitHub (Dec 22, 2023):

Yes, to both questions.

@BackNot commented on GitHub (Dec 22, 2023): Yes, to both questions.
Author
Owner

@mpdude commented on GitHub (Dec 22, 2023):

Are you aware that this is not a supported way of configuration?

Out of curiosity, may I ask why you’re doing it that way?

@mpdude commented on GitHub (Dec 22, 2023): Are you aware that this is not a supported way of configuration? Out of curiosity, may I ask why you’re doing it that way?
Author
Owner

@BackNot commented on GitHub (Dec 22, 2023):

I didn't know that it was not supported. I have entities that have the same set of 3-4 properties and schema and I thought that I can reuse it. Thanks for the info.

@BackNot commented on GitHub (Dec 22, 2023): I didn't know that it was not supported. I have entities that have the same set of 3-4 properties and schema and I thought that I can reuse it. Thanks for the info.
Author
Owner

@mpdude commented on GitHub (Dec 22, 2023):

Maybe a mapped superclass helps?

@mpdude commented on GitHub (Dec 22, 2023): Maybe a mapped superclass helps?
Author
Owner
@mpdude commented on GitHub (Dec 22, 2023): See the second yellow box at https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/reference/inheritance-mapping.html#inheritance-mapping
Author
Owner

@BackNot commented on GitHub (Dec 27, 2023):

I can confirm that mapped superclass solved my problem. I am going to close the issue.

@BackNot commented on GitHub (Dec 27, 2023): I can confirm that mapped superclass solved my problem. I am going to close the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7287