automatic discriminator discovery not namespace aware #5997

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

Originally created by @delboy1978uk on GitHub (Jun 22, 2018).

Originally assigned to: @Majkl578 on GitHub.

Bug Report

Q A
BC Break no
Version latest

Summary

Current behavior

Right now there has been one PR closed, and 2 still open for a @DiscriminatorValue since the entire discriminator map currently needs to go into the base class, which means extending classes in a different package will not work with it.

Currently we have an automatic discriminator map, just by removing the annotation. However, two classes with the same name regardless of the namespace will not work.

How to reproduce

<?php

namespace Del\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="Del\Repository\UserRepository")
 * @ORM\Table(name="User",uniqueConstraints={@ORM\UniqueConstraint(name="email_idx", columns={"email"})})
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="class", type="string")
 */
class User 
{
 // code
}

then try and extend it with another User class in a different namespace:

<?php

namespace OAuth;

use Del\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use League\OAuth2\Server\Entities\UserEntityInterface;

/**
 * @ORM\Entity(repositoryClass="OAuth\Repository\UserRepository")
 */
class User extends BaseUser implements UserEntityInterface
{
  // code
}

Expected behavior

Migrations will generate.

Originally created by @delboy1978uk on GitHub (Jun 22, 2018). Originally assigned to: @Majkl578 on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | latest #### Summary <!-- Provide a summary desciribing the problem you are experiencing. --> #### Current behavior Right now there has been one PR closed, and 2 still open for a `@DiscriminatorValue` since the entire discriminator map currently needs to go into the base class, which means extending classes in a different package will not work with it. Currently we have an automatic discriminator map, just by removing the annotation. However, two classes with the same name regardless of the namespace will not work. #### How to reproduce ```php <?php namespace Del\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass="Del\Repository\UserRepository") * @ORM\Table(name="User",uniqueConstraints={@ORM\UniqueConstraint(name="email_idx", columns={"email"})}) * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="class", type="string") */ class User { // code } ``` then try and extend it with another User class in a different namespace: ```php <?php namespace OAuth; use Del\Entity\User as BaseUser; use Doctrine\ORM\Mapping as ORM; use League\OAuth2\Server\Entities\UserEntityInterface; /** * @ORM\Entity(repositoryClass="OAuth\Repository\UserRepository") */ class User extends BaseUser implements UserEntityInterface { // code } ``` #### Expected behavior Migrations will generate.
admin added the BugCan't Fix labels 2026-01-22 15:24:29 +01:00
admin closed this issue 2026-01-22 15:24:29 +01:00
Author
Owner

@delboy1978uk commented on GitHub (Jun 25, 2018):

In the meantime, I have just renamed my second user class to OAuthUser. Not ideal but it works.

@delboy1978uk commented on GitHub (Jun 25, 2018): In the meantime, I have just renamed my second user class to OAuthUser. Not ideal but it works.
Author
Owner

@Majkl578 commented on GitHub (Jul 3, 2018):

Unfortunately this can't be changed in BC way so it will have to stay as is in ORM 2.x.
We may deprecate auto-discovery in 3.0 and replace it by @DiscriminatorValue, probably via #6612.

I'll leave it open, but there's nothing we can do in 2.x in this regard.

@Majkl578 commented on GitHub (Jul 3, 2018): Unfortunately this can't be changed in BC way so it will have to stay as is in ORM 2.x. We may deprecate auto-discovery in 3.0 and replace it by `@DiscriminatorValue`, probably via #6612. I'll leave it open, but there's nothing we can do in 2.x in this regard.
Author
Owner

@delboy1978uk commented on GitHub (Jul 5, 2018):

I thought that might be the case, thanks for letting me know!

@delboy1978uk commented on GitHub (Jul 5, 2018): I thought that might be the case, thanks for letting me know!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5997