mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Duplicate definition of column for a class with InheritanceType and that extend another class #7351
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @carross-tlhuillier on GitHub (Mar 29, 2024).
BC Break Report
Summary
If a class has InheritanceType attribute and it extend another class that has at least a property, it generate an error duplicate definication of column the properties in the extended class for orm v3.1.1 and v3.1.0, but worked for v2.7.5.
How to reproduce
The MappedSuperclass
The class with InheritanceType attribute
An inheritor class
Run
doctrine orm:schema-tool:update --dump-sql, generate the error@mpdude commented on GitHub (Dec 19, 2025):
Can you put StockTreeEntry in the discriminator map as well?
Can you make sure that all three classes/namespaces are registered in the mapping driver configurations?
@pounard commented on GitHub (Jan 20, 2026):
I confirm this bug, I experience it on many classes after upgrade in a project.
@pounard commented on GitHub (Jan 20, 2026):
My use case:
And many others, always the same schema, they all inherit from the root
AbstractRestEntityclass, it's always "X extends Y, Y extends AbstractRestEntity".I'm using 3.6.1 version.
@pounard commented on GitHub (Jan 20, 2026):
Problem seems to be in trait method
ReflectionBasedDriver::isRepeatedPropertyDeclaration(), when reaching here, in the above use case, inClassMetadata::$fieldMappings['id']theFieldMapping::$declaredstring value isTransactioninstead of beingAbstractRestEntity, which means that the following code:will not match and
ReflectionBasedDriver::isRepeatedPropertyDeclaration()will returnfalse.Because in
\ReflectionProperty::$classis set toAbstractRestEntity(it is where it's really being declared on the PHP code side).I guess that the problem is when the
FieldMapping::$declaredis set, when inheritance has more than one level, it's been overridden with lower inheritance tree class name instead of being kept where it was declared.@pounard commented on GitHub (Jan 20, 2026):
When I reach this:
With
$parentClass->namebeingTransaction, myidfield is broken, it doesn't have thedeclaredattribute set to the root parent classAbstractRestEntitywhich it should have. It's simplynull. This is where the bug happens, because the mapping does not have the root parent class name in itsdeclaredproperty, the property is being wrongly set to the current class instead of the parent one.@pounard commented on GitHub (Jan 20, 2026):
I don't known the ORM internals enough, but I'd say that when an class with the
MappedSuperclassattribute is instrospected, parenting information is lost in the way.@pounard commented on GitHub (Jan 20, 2026):
OK! No bug in the end, I found the reason. My classes are not in the same namespace, but the namespace the root abstract class is within is not covered by a MappingDriver!
This causes the class to be excluded from parent class list when building child classes metadata, and properties are found and attached in the closest parent in the inheritance tree which is in a MappingDriver path.
In my case,
AbstractRestEntitywas not in a declared namespace, butTransactionwas. SoTransactioninherited from allAbstractRestEntityproperties as if it was its own.It's kind of tricky, and I think this is kind of a wrong behavior, any parent class should be considered using the same driver as the child if no namespace is declared, it would prevent this kind of very weird behavior.
The magic that pointed this to me lies in the
AbstractClassMetadataFactoryclass in:This was a wild journey the head in xdebug to find this, ORM code is not simple (not complaining, the tool is really great).
@davidnectarestudio commented on GitHub (Jan 21, 2026):
@pounard I think that it is same problem here https://github.com/doctrine/orm/issues/12246
@mpdude commented on GitHub (Jan 21, 2026):
I have seen the pattern that a class not being covered by mapping configuration leads to "duplicate column" error way too oftern – just debugging one of these cases in a project myself, but at least I know what to look out for.
I'd need more time to think about under which conditions and where a helpful error message could be given.