orm icon indicating copy to clipboard operation
orm copied to clipboard

Multiple inheritance mapped superclasses in different namespaces

Open cyrilverloop opened this issue 1 year ago • 2 comments

Bug Report

Q A
BC Break yes/no
Version 2.19 => 3.2

Summary

Hi,

On a Symfony 7 app, you can not have multiple inheritance mapped superclasses in different namespaces.

May be related to : https://github.com/doctrine/orm/issues/11404

Current behavior

Generating the migrations with ./bin/console make:migration gives the error : Duplicate definition of column 'id' on entity 'App\Entity\Daughter' in a field or discriminator column mapping.

How to reproduce

<?php

declare(strict_types=1);

namespace App\SomewhereElse;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\MappedSuperclass()]
abstract class BaseEntity
{
    #[
        ORM\Id(),
        ORM\Column(type: Types::INTEGER),
        ORM\GeneratedValue(strategy: "AUTO")
    ]
    protected ?int $id;
}
<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\MappedSuperclass()]
abstract class BaseEntity
{
    #[
        ORM\Id(),
        ORM\Column(type: Types::INTEGER),
        ORM\GeneratedValue(strategy: "AUTO")
    ]
    protected ?int $id;
}
<?php

declare(strict_types=1);

namespace App\Entity;

use App\SomewhereElse\BaseEntity; // Comment this line to make the problem disappear.
use Doctrine\ORM\Mapping as ORM;

#[ORM\MappedSuperclass()]
abstract class Mother extends BaseEntity {}
<?php

declare(strict_types=1);

namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class Daughter extends Mother {}

If App\Entity\Mother extends App\SomewhereElse\BaseEntity, the error appears (report_fields_where_declared: true with ORM 2.x). If App\Entity\Mother extends App\Entity\BaseEntity, it works.

Expected behavior

I would like to be able to extend mapped superclasses from libraries (other namespaces).

cyrilverloop avatar Jun 03 '24 19:06 cyrilverloop

@cyrilverloop Did you find a way to make this work ? Other than not using abstraction

nathan-de-pachtere avatar Feb 12 '25 16:02 nathan-de-pachtere

@nathan-de-pachtere sorry, no. What seems to work is having only one abstract class on the hierarchy (even on 3.3.2).

cyrilverloop avatar Feb 12 '25 18:02 cyrilverloop

I have tried to reproduce this issue in #12157, but was not successful (could not demonstrate the problem).

mpdude avatar Sep 04 '25 14:09 mpdude

@cyrilverloop Can you make sure that all involved classes are actually seen by Doctrine as mapped classes?

In a Symfony app, use the doctrine:mapping:info command to find out.

mpdude avatar Sep 04 '25 16:09 mpdude

@mpdude I'll try to reproduce it tomorrow.

cyrilverloop avatar Sep 04 '25 16:09 cyrilverloop

Also check: Do you happen to mix different mapping drivers for the different namespaces?

mpdude avatar Sep 04 '25 17:09 mpdude

I can reproduce it with doctrine/orm 3.5.2.

You can find example entities on a simple demo at : git clone -b doctrine-11488 --single-branch [email protected]:cyrilverloop/symfony-demo.git

doctrine:mapping:info will show you the error message.

Do you happen to mix different mapping drivers for the different namespaces?

I do not think so.

cyrilverloop avatar Sep 05 '25 14:09 cyrilverloop