doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

Duplicate definition of column for a class with InheritanceType and that extend another class #11404

Open carross-tlhuillier opened 3 months ago

carross-tlhuillier commented 3 months ago

BC Break Report

Q A
BC Break yes
Version 3.1.1

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.

In MappingException.php line 420:
Duplicate definition of column 'id' on entity 'Entity\CategoryLink' in a field or discriminator column mapping. 

How to reproduce

The MappedSuperclass

namespace MappedSuperClass;

use \Doctrine\ORM\Mapping as ORM;

#[ORM\MappedSuperclass]
abstract class AbstractEntity {

    #[ORM\Column(name: 'id', type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue]
    protected ?int $id = null;
}

The class with InheritanceType attribute

namespace Entity;

use \Doctrine\ORM\Mapping as ORM;
use \MappedSuperClass\AbstractEntity;

/**
 * @property mixed $Linked
 */
#[ORM\Entity]
#[ORM\Table(name: 'stock_tree')]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'discriminator', type: 'string')]
#[ORM\DiscriminatorMap([
    'Category' => \Entity\CategoryLink::class
])]
class StockTreeEntity extends AbstractEntity {
}

An inheritor class

namespace Entity;

use \Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'categories_link')]
class CategoryLink extends StockTreeEntity {

}

Run doctrine orm:schema-tool:update --dump-sql, generate the error

In MappingException.php line 420:
Duplicate definition of column 'id' on entity 'Entity\CategoryLink' in a field or discriminator column mapping.