mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2772: One class can be mapped to multiple discriminator values #3467
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 @doctrinebot on GitHub (Nov 1, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user mouyang:
I'm not sure if this is intentional or not, but this appears to a valid discriminator map. The problem I am running into is that it's impossible to create an instance of ClassB with a discriminator value "DiscB" (it's always "DiscC" - I'm assuming last one wins here).
Eventhough DiscB and DiscC map to the same class, I do want to maintain some sort of logical separation in the database using the two discriminator values. That does not appear to be possible. I can provide more details about my data model, if necessary.
These are the possible solutions I can think of.
@guilhermeblanco commented on GitHub (Jan 3, 2017):
Our intended solution is 1. "Enforce a strict one-to-one relationship between value and class. This means I would have to modify my code to reflect this."
An enforcement should be added restricting people to map multiple discriminator values to a single class. This should be done at mapping level by checking
count(array_unique($map)) === count($map)and adding a MappingException if it doesn't match.@beberlei commented on GitHub (May 12, 2022):
This makes sense for ORM 3.0 but also requires a deprecation message to be thrown in 2.x
@derrabus commented on GitHub (May 12, 2022):
Do you want to work on it? 🙃
@javijavo commented on GitHub (May 13, 2022):
Hello,
I would like to ask why is this not possible?
If I have a let's say two possible classes Mammals and Reptiles and I want to discriminate "cat", "dog" to Mammals and "turtle" to Reptile? How do we do it after this deprecation?
(The example is very basic but I have some entity that works thay way)
Thanks
@beberlei commented on GitHub (May 13, 2022):
@javijavo but there is no way to new Mamal() and have it stored as either dog or cat. Do you create these entities outside the ORM?
@javijavo commented on GitHub (May 13, 2022):
I have a very old and huge legacy application progressively adating it to Doctrine and yes the data is already stored.
But I see the problem of having multiple values, didn't have in mind the "standard" scenario instead my ugly one.
Will look for another way to meet my requirements.
Thanks
@oleg-andreyev commented on GitHub (Oct 1, 2025):
Having similar issue...
we have and ERP (Windows App) that we cannot control or change, but we need some sort of API and we need to have multiple values for same class
and unfortunately for me... I get it why it impossible...
when doing
new CreditNote()we don't know under which discriminatorValue to write N0SB or K3SB...